2013-06-02 2 views
9

golang에 대해 database/sql 패키지를 사용하여 Microsoft SQL Server 데이터베이스에 연결하려고합니다.Windows7 64 비트 용 Golang MSSQL 드라이버

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 repo에 공개 문제로 나열됩니다.

누구든지 64 비트 Windows 7 클라이언트에서 MSSQL 데이터베이스에 연결 한 경험이 있습니까? 어떤 odbc 드라이버가 권장됩니까?

+1

https://code.google.com/p/odbc – alex

+0

Alex, 해당 드라이버를 사용하여 sql.Open() 호출의 예를 제공 할 수 있습니까? DSN을 사용해야하거나 연결 문자열을 지정할 수 있습니까? 감사. – slachterman

+1

https://code.google.com/p/odbc/source/browse/mssql_test.go#56 – alex

답변

7

대신 ODBC 드라이버를 사용해보십시오, 나는 그것이 더 널리 사용되는 믿습니다 https://code.google.com/p/odbc/ 이제

+0

또한, 플랫폼에 따라, ODBC 클라이언트 (특히 윈도우가 아닌)에 대해'Microsoft ODBC SQL Adapter'를 통해'FreeTDS'를 사용해야 할 수도 있습니다. – Tracker1

9

는, 순수 이동 패키지 GitHub의에서 데이터베이스 드라이버 목록 SQL database drivers에서 Microsoft SQL Server 관련 드라이버가 https://github.com/denisenkom/go-mssqldb

go-mssqldb을 시도하면 mssql에 직접 연결할 수 있습니다.

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

내가 그것을 사용하고, 그것이 지금은 괜찮습니다 :

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

sql.Open()은 다음과 같습니다처럼

import

는 볼 수 있었다.

+2

이 링크가 질문에 대답 할 수 있지만 여기에 답의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – juliocesar

관련 문제