This is a creation in Article, where the information may have evolved or changed.
SQL Server 2008 Configuring the remote connection method, refer to Baidu Experience: http://jingyan.baidu.com/article/6c67b1d6ca06f02787bb1ed1.html
The Golang connection remote method is as follows:
Package Mainimport ("Database/sql" "FMT" "Strings") Import (_ "Github.com/mattn/go-adodb") type Mssql struct {*sql. Dbdatasource stringdatabase stringwindows boolsa sa}type SA struct {user stringpasswd stringport Int}func (M *mssql) Open () (err error) {var conf []stringconf = append (conf, "provider=sqloledb") conf = append (conf, "Data source=" +m.datasour CE) if m.windows {///Integrated SECURITY=SSPI This indicates that the current Windows system user is logged in to the SQL Server server (which needs to be set at the time of installation of SQL Servers),//If SQL An error occurs when the server server does not support this way of logging on. conf = append (conf, "Integrated SECURITY=SSPI")}conf = append (conf, "Initial catalog=" +m.database) conf = append (conf, "us Er id= "+m.sa.user) conf = append (conf," password= "+m.sa.passwd) conf = append (conf," port= "+fmt. Sprint (M.sa.port)) m.db, err = sql. Open ("ADODB", strings. Join (conf, ";")) If err! = Nil {return Err}return Nil}func main () {db: = Mssql{datasource: "10.10.2.140\\sqlexpress", Database: "Test",// Windwos:true for Windows authentication, false must set SA account and password windows:false,sa:sa{user: "sa", passwd: "123456 ", port:1433,},}//connection Database err: = db. Open () if err! = Nil {fmt. PRINTLN ("SQL Open:", err) Return}defer db. Close ()//Execute SQL statement rows, err: = db. Query ("SELECT * FROM Info") If err! = Nil {fmt. PRINTLN ("Query:", err) return}for rows. Next () {var name stringvar number introws. Scan (&name, &number) fmt. Printf ("name:%s \ t:%d\n", Name, Number)}}