我正在尝试连接到CentOS 5.8上的SQL Server 2008。我使用的是unixODBC 2.3.0和SQL Server ODBC驱动程序(http://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 ", 4}, {"1 ", 4}, {"1 ", 4}, {" ", 1}, {" ", 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)
显然,建立联系有问题。
有人能帮我吗?如果你需要任何其他信息,请告诉我。
感谢
在使用linux和odbc时,使用Microsoft的linux驱动程序连接到Microsoft的SQL Server,其中一个'gotcha'是odbc.ini中用于服务器的字符串,该字符串也必须包含端口。
Server = [protocol:]server[,port]
根据http://msdn.microsoft.com/en-us/library/hh568455.aspx这与使用port = <portnumber>
约定的大多数其他设置不同。如果未配置,您将看到"无法SQLConnect"错误。
还要确保使用了正确的odbc文件。
odbcinst -j
将显示配置的源及其位置。
您稍后可能会遇到的另一个问题是,如果odbc.ini中的用户和密码信息是纯文本的,那么SQL Server的驱动程序会忽略这些信息,因此请确保您的应用程序能够处理这些信息。
要调试问题,请尝试以下步骤:
- telnet<1433>
- 转到SQL server网络配置
- TCP/IP设置
- 右键单击并打开属性
- 切换到网络属性选项卡
- 在
IPAll
属性下,将动态端口设置为空白,并将端口设置为1433
- 重新启动SQL服务
您可以打开odbc跟踪并使用tcpdump捕获网络包。我认为odbc跟踪会有所帮助。
问题是我将EL6驱动程序与EL5一起使用。安装正确的版本后,一切正常。无论如何,感谢大家的回复。