首页 > 解决方案 > Perl 脚本无法使用 ODBC 连接到 MS SQL:“连接字符串无效”

问题描述

脚本 test.pl

use DBI;
$dbh = DBI->connect(
    "dbi:ODBC:" .
    "Driver={/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.5.so.2.1};" .
    "Server=10.3.0.241;" .
    "Database=TEST;" .
    "UID=test;" .
    "PWD=test123"
);

结果

DBI connect('Driver={/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.5.so.2.1};Server=10.3.0.241,0;Database=TEST;UID=test;PWD=test123','',...) failed: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (SQL-HYT00) [state was HYT00 now 08001]
[Microsoft][ODBC Driver 17 for SQL Server]MAX_PROVS: Connection string is not valid [87].  (SQL-08001)
[Microsoft][ODBC Driver 17 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. (SQL-08001) at ./test.pl line 6.

服务器老板说:你连接不上1433端口,我们用的是SSMS,端口会自动连接

标签: sql-serverperlodbcconnection-string

解决方案


服务器=10.3.0.241;变成服务器=10.3.0.241\MSSQL;

然后我的 linux 可以通过 udp/1443 与 windows 服务器通信,并相互了解在哪个 tcp 端口上继续通信。


推荐阅读