The following steps let me connect to Db2 from golang on Windows7 pro x64. Your mileage may vary.
I Used a recent "Db2 Runtime Client" package for Windows x64 downloadable from IBM website (in my case that was version 220.127.116.11b) and the filename I downloaded was
This is installed locally at location
"c:\Program Files\IBM\sqllib" location (default).
I have already a working gcc installed on Windows7 for other projects (it may be from minGW).
I verified in a db2cmd.exe window that I can successfully connect via the CLP (which uses CLI) to the database of interest, using a specific port number and specific credentials. This way I know that the Db2-client is installed properly, and the Db2-server is running, the database is available, and credentials and port are all OK.
Running as local administrator, Installed go for Windows from msi file downloaded from golang.org/dl to default location
phiggins-db2cli-*.zip from https://bitbucket.org/phiggins/db2cli
Created local directory:
Unzipped contents of the phiggins-db2cli-*.zip into
In a db2cmd.exe window running as Adminstrator:
Created a batch file
buildgo.bat with the following contents:
set DB2HOME="C:\program files\ibm\sqllib" set CGO_LDFLAGS=-L"C:\Program Files\IBM\sqllib\lib" set CGO_CFLAGS=-I"C:\Program Files\IBM\sqllib\include" go build .
In a db2cmd window running as administrator, ran the batchfile, it completed without errors or messages with errorlevel 0.
In the same db2cmd window, created a file containing the sample program shown at https://bitbucket.org/phiggins/db2cli
The file I created was called
I then execute the sample program:
go run testgo.co -conn DATABASE=sample;HOSTNAME=whatever;PORT=60000;UID=whatever;PWD=whatever;
--> successfully get the result set on screen