sla*_*man 9 sql-server 64-bit go windows-7-x64
我正在尝试使用golang的数据库/ sql包连接到Microsoft SQL Server数据库.
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 repo中的一个未解决的问题.
有没有人有从64位Windows 7客户端连接到MSSQL数据库的经验?建议使用哪种odbc驱动程序?
小智 9
现在,github 上的数据库驱动程序列表SQL数据库驱动程序上有一个Microsoft SQL Server特定的驱动程序,带有一个纯Go包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
)
Run Code Online (Sandbox Code Playgroud)
的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()
Run Code Online (Sandbox Code Playgroud)
我正在使用它,现在还可以.