sql-server - 适用于 Windows7 64 位的 Golang MSSQL 驱动程序

标签 sql-server 64-bit go windows-7-x64

我正在尝试使用 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/

相关文章:

c# - Crystal Report 不支持 64 位机器

string - 将字符串作为字符数组访问以在 strings.Join() 方法中使用 : GO language

sorting - 转换类型进行排序 : any runtime cost?

go - 解释:function returns same function in go

sql - 如何在我的用户表中散列管理员密码?

c# - 有没有办法可以生成 CRM 中所有实体的列表以及它们是否打开了审核历史记录?

sql - 如果表中的两列具有相同的值,则获取单行

sql-server - 获取当前 Sp 参数和值 - (类似反射)?

linux - 是什么导致了 glBufferSubData 中的这个 opengl 段错误?

64-bit - 如何在 x64 窗口中运行 PartCover