无法从Linux连接到SQl Server

时间:2013-02-27 02:50:23

标签: sql-server-2008 unixodbc strace isql sqlncli

我正在尝试连接到CentOS 5.8上的SQL Server 2008。我使用的是unixODBC 2.3.0和SQL Server ODBC驱动程序(www.microsoft.com/en-us/download/details.aspx?id=28160)。

当我尝试通过运行来测试连接时:

isql -v mydsn username password
它给了我:

[S1T00][unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired
[08001][unixODBC][Microsoft][SQL Server Native Client 11.0]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.
[08001][unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0x2726
[ISQL]ERROR: Could not SQLConnect

端口已打开,服务器可以访问。

我试图进一步诊断问题,但卡在这里:

 strace -e trace=network isql -v mydsn username password
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = -1 ENOENT (No such file or directory)
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = -1 ENOENT (No such file or directory)
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/var/run/setrans/.setrans-unix"...}, 110) = 0
sendmsg(3, {msg_name(0)=NULL, msg_iov(5)=[{"\1\0\0\0", 4}, {"\1\0\0\0", 4}, {"\1\0\0\0", 4}, {"\0", 1}, {"\0", 1}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 14
socket(PF_FILE, SOCK_STREAM, 0)         = 4
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = -1 ENOENT (No such file or directory)
socket(PF_FILE, SOCK_STREAM, 0)         = 4
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = -1 ENOENT (No such file or directory)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)

显然,建立连接存在一些问题。

任何人都可以帮助我吗?如果您需要任何其他信息,请与我们联系。

由于

4 个答案:

答案 0 :(得分:9)

使用Microsoft的Linux驱动程序时,使用linux和odbc连接到Microsoft SQL Server时,一个'问题'是服务器的odbc.ini中的字符串也必须包含该端口。

 Server = [protocol:]server[,port]

按照http://msdn.microsoft.com/en-us/library/hh568455.aspx 这与使用port = <portnumber>约定的大多数其他设置不同。如果未配置,您将看到“无法SQLConnect”错误。

还要确保使用正确的odbc文件。

odbcinst -j

将显示已配置的来源及其位置。

稍后您可能会遇到的另一个问题是SQL Server的驱动程序会忽略odbc.ini中的用户和密码信息(如果它是纯文本的),因此请确保您的应用程序处理该信息。

答案 1 :(得分:1)

要调试此问题,请尝试以下步骤:

  1. telnet&lt; 1433&gt;
  2. 转到SQL服务器网络配置
  3. TCP / IP设置
  4. 右键单击并打开属性
  5. 切换到网络媒体资源标签
  6. IPAll属性下将动态端口设置为空白并将端口设置为1433
  7. 重新启动SQL服务

答案 2 :(得分:0)

您可以打开odbc跟踪并使用tcpdump来捕获网络包。我认为odbc跟踪会提供帮助。

答案 3 :(得分:0)

问题是我在EL5上使用EL6驱动程序。安装正确的版本后,一切正常。谢谢大家的回应。