<p>any example of how to connect and run a query?</p>
<hr/>**评论:**<br/><br/>ackondro: <pre><p>I'd use <a href="https://github.com/denisenkom/go-mssqldb" rel="nofollow">https://github.com/denisenkom/go-mssqldb</a> with something like the folowing:</p>
<pre><code>package main
import (
"database/sql"
"fmt"
_ "github.com/denisenkom/go-mssqldb"
)
func main() {
dsn := "server=localhost;user id=me;password=pass;database=my_db
db, err := sql.Open("mssql", dsn)
if err != nil {
fmt.Println("Cannot connect: ", err.Error())
return
}
err = db.Ping()
if err != nil {
fmt.Println("Cannot connect: ", err.Error())
return
}
defer db.Close()
rows, err := db.Query("SELECT users.id FROM users WHERE users.age = ?", 12)
if err != nil {
fmt.Println("Cannot query: ", err.Error())
return
}
defer rows.Close()
for rows.Next() {
var val []interface{}
err = rows.Scan(val...)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(val)
}
}
</code></pre></pre>