且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用 PYODBC 连接到网络外的远程 SQL Server

更新时间:2023-02-03 18:43:16

我终于找到了答案(在尝试解决连接到 Azure 上托管的 SQL Server 的问题时偶然发现的).PYODBC 连接字符串,如果连接到 SQL Server 所在网络的外部,则需要一个端口号,而不是像其他 SQL 包使用的那样假设默认值.只需在连接字符串中添加 'PORT=1433;' 即可使连接正常工作.PYODBC 似乎对它何时使用并且不想使用默认端口进行连接很挑剔.

I have finally figured out what the answer is (by accident while trying to also troubleshoot connecting to a SQL Server hosted on Azure). The PYODBC connection string, if connecting outside of the network the SQL Server is on, requires a port number, rather than assuming the default like other SQL packages use. Simply adding 'PORT=1433;' to the connection string got the connection to work. PYODBC seems to be picky about when it does and doesn't want to use the default port for connections.