在 RHEL 6 上使用 sqlcmd 和 odbc 驱动程序连接到 MSSQL 服务器失败

Chr*_*ris 6 redhat sql-server unixodbc

我花了最后一个小时试图通过 odbc 驱动程序使用 sqlcmd 连接到 mssql 服务器。我正在和 db 的人交谈,但他似乎不知道发生了什么.. 也许你可以帮我找出一些我可以问那个人的问题..

我正在使用 Microsoft 的官方 odbc 驱动程序。显然我们正在使用某种动态端口。

中间没有防火墙。

# odbcinst -q -d -n
[PostgreSQL]
[MySQL]
[ODBC Driver 11 for SQL Server]
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法

错误代码 0x2AF9:

sqlcmd -S hostname\DEV04 -U username -P password
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: Microsoft ODBC Driver 11 for SQL Server : TCP Provider: Error code 0x2AF9.
Run Code Online (Sandbox Code Playgroud)

定位指定的服务器/实例时出错 [xFFFFFFFF]。

sqlcmd -S hostname\\DEV04 -U username -P password
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: Microsoft ODBC Driver 11 for SQL Server : SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. 
Run Code Online (Sandbox Code Playgroud)

使用 perl

DBI connect('DASHBOARD','username',...) failed: [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired (SQL-HYT00) [state was HYT00 now 08001]
[unixODBC][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. (SQL-08001)
[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].  (SQL-08001) at ./test.pl line 4
Can't connect to : [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired (SQL-HYT00) [state was HYT00 now 08001]
[unixODBC][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. (SQL-08001)
[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].  (SQL-08001) at ./test.pl line 4.
Run Code Online (Sandbox Code Playgroud)

小智 0

我遇到了类似的问题。事实证明,\DEV04的部分hostname\DEV04用于指示客户端应该在与默认端口不同的端口上连接到服务器。在 Microsoft 世界中,DEV04自动使用可确保客户端连接到正确的端口...但这似乎不适用于 Linux sqlcmd。

询问 SQL Server 管理员实例\DEV04正在侦听哪个端口并使用哪个端口进行连接hostname,PORT