在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
import _ "github.com/denisenkom/go-mssqldb" import ( "crypto/cipher" "crypto/des" "crypto/md5" "database/sql" "encoding/hex" "encoding/json" "fmt" "net/http" _ "odbc/driver" "strconv" "bytes" "flag" "log" ) var debug = flag.Bool("debug", true, "enable debugging") var password = flag.String("password", "a*c23**", "the database password") var port *int = flag.Int("port", 6003, "the database port") var server = flag.String("server", "123.***.120.**", "the database server") var user = flag.String("user", "sa", "the database user") var database = flag.String("database", "Deer_JNCB_********", "the database name") func GetDB() (*sql.DB, error){ 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;database=%s;user id=%s;password=%s;port=%d;encrypt=disable", *server, *database, *user, *password, *port) if *debug { fmt.Printf(" connString:%s\n", connString) } db, err := sql.Open("mssql", connString) if err != nil { log.Fatal("Open connection failed:", err.Error()) return nil, err } err = db.Ping() if err != nil { fmt.Print("PING:%s",err) return nil, err } return db, nil } encrypt=disable 这个很重要,说三遍..... |
请发表评论