现在,数据库驱动程序列表中有一个 Microsoft SQL Server 特定驱动程序 github 中的SQL 数据库驱动程序带有纯 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()
我正在使用它,现在还可以。