Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang MSSQL driver for Windows7 64-bit

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?

like image 308
slachterman Avatar asked Jun 02 '13 18:06

slachterman


2 Answers

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.

like image 193
Sheppard Y Avatar answered Sep 25 '22 11:09

Sheppard Y


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

like image 26
voidlogic Avatar answered Sep 25 '22 11:09

voidlogic