我正在尝试使用 golang 的 database/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:抱歉,未实现:64 位模式未编译
。这在 github 存储库中被列为 Unresolved 问题。
有人有从 64 位 Windows 7 客户端连接到 MSSQL 数据库的经验吗?推荐哪个 odbc 驱动?
最佳答案
现在,数据库驱动程序列表中有一个 Microsoft SQL Server 特定驱动程序 SQL database drivers在 github 中使用纯 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
)
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()
我正在使用它,暂时还可以。
关于sql-server - 适用于 Windows7 64 位的 Golang MSSQL 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16885940/