上一篇讲了如何安装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

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

被折叠的 条评论
为什么被折叠?



