This is a creation in Article, where the information may have evolved or changed.
The go language accesses SQL Server through ODBC, which needs to use the GO-ODBC Library, open Source address:: Https://github.com/weigj/go-odbc
First, drive installation
Open the Gopath in cmd:
Go to src Directory
In the SRC directory, get the ODBC driver via git:
git clone git://github.com/weigj/go-odbc.git ODBC
Go to the ODBC directory:
Run the Go Install command:
prompt does not install GCC compiler, to the official website download http://tdm-gcc.tdragon.net/ .
Ii. installation of GCC
or download Mingw-w64-install.exe (170.0 KB), reboot after installation.
is the Mingw-w64-install.exe (https://sourceforge.net/projects/mingw-w64/) installation process:
Configure the GCC environment, open system variables, modify path, add E:\Program files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin, such as:
Run the Go install command again without prompting for an error message, such as:
Iii. Examples of programs
Idea: Link database--Create a query--display query results
Package Mainimport ("FMT" "ODBC") Func main () {FMT. Printf ("%s\n", "CREATE Database Link") conn, _: = ODBC. Connect ("DSN=DTCMS; Uid=user; Pwd=admin@163.com ") stmt, _: = conn. Prepare ("SELECT top * from Dt_article") stmt. Execute () rows, err: = stmt. Fetchall () if err! = Nil {fmt. PRINTLN (Err) return}for I, row: = Range rows {Println (i, Row)}stmt. Close () Conn. Close () return}