2013-06-02 46 views
9

我試圖使用golang的數據庫/ sql包連接到Microsoft SQL Server數據庫。適用於Windows7的Golang MSSQL驅動程序64位

https://code.google.com/p/go-wiki/wiki/SQLDrivers沒有列出MSSQL特定的驅動程序,所以我想我會嘗試一個odbc驅動程序。

我試過https://github.com/weigj/go-odbc但是當我運行go install我收到 cc1.exe: sorry, unimplemented: 64-bit mode not compiled in。這被列爲github回購中的一個公開問題。

有沒有人有從64位Windows 7客戶端連接到MSSQL數據庫的經驗?推薦哪個odbc驅動程序?

+1

https://code.google.com/p/odbc – alex

+0

亞歷克斯,你能提供一個使用該驅動程序的sql.Open()調用的例子嗎?是否需要使用DSN或可以指定連接字符串?謝謝。 – slachterman

+1

https://code.google.com/p/odbc/source/browse/mssql_test.go#56 – alex

回答

7

嘗試使用此ODBC驅動程序,而不是,我相信這是更廣泛的應用:https://code.google.com/p/odbc/

+0

此外,根據您的平臺,ODBC客戶端(特別是非Windows)可能需要在Microsoft ODBC SQL Adapter上使用'FreeTDS'。 – Tracker1

9

現在,有數據庫驅動程序列表SQL database drivers在Microsoft SQL Server特定的驅動程序在github上與純圍棋包https://github.com/denisenkom/go-mssqldb

您可以嘗試go-mssqldb直接連接mssql

import可能看起來像:

import (
    "fmt" 
    "log" 
    "database/sql" 
    _ "github.com/denisenkom/go-mssqldb"  // the underscore indicates the package is used 
)  

sql.Open()樣子:

// the user needs to be setup in SQL Server as an SQL Server user. 
// see create login and the create user SQL commands as well as the 
// SQL Server Management Studio documentation to turn on Hybrid Authentication 
// which allows both Windows Authentication and SQL Server Authentication. 
// also need to grant to the user the proper access permissions. 
// also need to enable TCP protocol in SQL Server Configuration Manager. 
condb, errdb := sql.Open("mssql", "server=localhost;user id=gouser;password=g0us3r;") 
if errdb != nil { 
    fmt.Println(" Error open db:", errdb.Error()) 
} 

defer condb.Close() 

,我使用它,這是確定的了。

+2

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – juliocesar

相關問題