go 连接mssql
go 连接mssql
package main import ( "database/sql" "fmt" "log" _ "github.com/denisenkom/go-mssqldb" ) func main() { connectString := "server=127.0.0.1;database=yndb;user id=sa;password=sql;port=8829;encrypt=disable" println("Connection string=", connectString) db, err := sql.Open("mssql", connectString) defer db.Close() println("Open Error:", err) if err != nil { log.Fatal(err) } // 执行SQL语句 rows, err := db.Query("select * from tunit") if err != nil { fmt.Println("query: ", err) return } for rows.Next() { var id string var name int rows.Scan(&id, &name) fmt.Printf("id: %s \t name: %d\n", id, name) } println("closing connection") db.Close() }
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/15208656.html