ubuntu下使用unixODBC+ODBC Driver 11 for SQL Server 连接SQL Server

本文详细介绍了在遇到ODBC连接SQLServer失败的问题时的排查步骤,通过配置ODBC.ini和odbcinst.ini文件,以及使用sqlcmd和代码连接SQLServer的过程。特别强调了SQLServer的两种认证方式,并通过代码实例展示了成功连接的方法。

上一篇讲了如何安装unixODBC+ODBC Driver 11 for SQL Server,安装完毕以后,我发现其实使用DSN方式根本就不能连接到数据库.在配置了DSN

<pre name="code" class="cpp">sudo vim /etc/odbc.ini

[mhdsn]
Driver = /opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Description = Microsoft ODBC Driver 11 for SQL Server
Trace = Yes
Server = 111.111.111.111
Port = 1433
Database = mhdb
Socket=tcp
 而另一个配置则为 

  ~  cat /etc/odbcinst.ini 

[ODBC Driver 11 for SQL Server]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Threading=1
UsageCount=1

[ODBC]
Trace = Yes
TraceFile = /tmp/odbc.log

在这情况下,我使用微软的sqlcmd连接服务器,是失败的,原因不知道,情况如下:

➜  ~  sqlcmd -S mhdsn
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd: Error: Microsof
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值