连接sqlserver
连接sqlserver
package main
import (
"database/sql"
"fmt"
_ "github.com/denisenkom/go-mssqldb"
)
func initSqlServer() {
c, err := sql.Open("sqlserver", "sqlserver://user:pwd@ip:port/db")
if err != nil {
fmt.Println(err)
return
}
err = c.Ping()
if err != nil {
fmt.Println(err)
return
}
var name string
err = c.QueryRow("select name from user limit 1").Scan(&name)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(name)
}
func main() {
initSqlServer()
}
选择了IT,必定终身学习