我想连接一个MSSQL
数据库,在python中我连接到这个数据库,但在Go
我不能。
当我执行此代码时,我收到此错误:
2017/08/04 12:25:39选择失败:登录错误:EOF
为什么?
代码:
package main
import (
"database/sql"
"flag"
"fmt"
"log"
_ "github.com/denisenkom/go-mssqldb"
)
var (
debug = flag.Bool("debug", false, "enable debugging")
password = flag.String("password", "********", "the database password")
port *int = flag.Int("port", 1433, "the database port")
server = flag.String("server", "sql2008v\\2k8", "the database server")
user = flag.String("user", "usuario", "the database user")
)
func main() {
flag.Parse()
if *debug {
fmt.Printf(" password:%s\n", *password)
fmt.Printf(" port:%d\n", *port)
fmt.Printf(" server:%s\n", *server)
fmt.Printf(" user:%s\n", *user)
}
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d", *server, *user, *password, *port)
if *debug {
fmt.Printf(" connString:%s\n", connString)
}
conn, err := sql.Open("mssql", connString)
if err != nil {
log.Fatal("Open connection failed:", err.Error())
}
defer conn.Close()
rows, err := conn.Query("SELECT TOP (1000) * FROM [jiradb].[jiraschema].[jiraissue]")
if err != nil {
log.Fatal("Select failed:", err.Error())
}
defer rows.Close()
fmt.Printf("bye\n")
}