dsm1998 2015-04-09 02:14
浏览 115

无法使用Go连接到MS SQL Server

I am trying to connect to sql server express using go and this sql driver "github.com/denisenkom/go-mssqldb"

Currently it calls open then stalls on the ping command, it never pings or returns an error.

I am using winauth and it works with sql management studio.

I have verified the database name, if I put a false one in, an error is generated and logged at the open step.

I have tried setting a really short connection time out but the same thing happens.

I have tried connecting to a remote sql server and it works correctly. The remote server is a developer version of sql server and had a name like xyz.abc.123 where my local sql express is called machine-name\sqlexpress.

Here is a sample program.

package main

import (
    "database/sql"
    _ "github.com/denisenkom/go-mssqldb"
    "log"
)

func main() {

    log.Println("Main:")

    log.Println("Opening")
    db, err := sql.Open("mssql", "server=Machine-Name\\SQLEXPRESS; database=MyDatabaseName;")

    if err != nil {
        log.Println("Open Failed: ", err.Error())
    }
    log.Println("Opened")

    log.Println("Pinging")
    err = db.Ping();
    if err != nil {
        log.Println("Failed to ping: ", err.Error())
    }

    log.Println("Pinged")
}
  • 写回答

2条回答 默认 最新

  • duanlou7910 2015-04-09 02:41
    关注

    This https://code.google.com/p/odbc/ driver works with MS SQL Server for me.

    Alex

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题