Golang MSSQL驱动程序适用于Windows7 64位操作系统。

huangapple go评论134阅读模式
英文:

Golang MSSQL driver for Windows7 64-bit

问题

我正在尝试使用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: sorry, unimplemented: 64-bit mode not compiled in的错误。这在github仓库中被列为一个未解决的问题。

有没有人有从64位Windows 7客户端连接到MSSQL数据库的经验?推荐使用哪个odbc驱动程序?

英文:

I am trying to connect to a Microsoft SQL Server database using the database/sql package for golang.

There is no MSSQL-specific driver listed at https://code.google.com/p/go-wiki/wiki/SQLDrivers, so I thought I'd try an odbc driver.

I tried https://github.com/weigj/go-odbc but when I run go install I receive
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in. This is listed as an open issue in the github repo.

Does anyone have experience connecting to an MSSQL database from a 64-bit Windows 7 client? Which odbc driver is recommended?

答案1

得分: 10

现在,在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"     // 下划线表示该包被使用
)    

sql.Open()部分可能如下所示:

// 用户需要在SQL Server中设置为SQL Server用户。
// 参见创建登录和创建用户的SQL命令以及SQL Server Management Studio文档以启用混合身份验证
// 允许Windows身份验证和SQL Server身份验证。
// 还需要为用户授予适当的访问权限。
// 还需要在SQL Server配置管理器中启用TCP协议。
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()

我正在使用它,目前还好。

英文:

Now, there is a Microsoft SQL Server specific driver on the database driver list SQL database drivers in github with a pure Go package https://github.com/denisenkom/go-mssqldb

You could try go-mssqldb to connect mssql directly.

The import could look like:

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

the sql.Open() looks like:

// 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()

and I am using it, it's ok for now.

答案2

得分: 7

尝试使用这个ODBC驱动程序,我相信它被更广泛地使用:https://code.google.com/p/odbc/

英文:

Try using this ODBC driver instead, I believe it is more widely used: https://code.google.com/p/odbc/

huangapple
  • 本文由 发表于 2013年6月3日 02:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/16885940.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定