【发布时间】:2018-11-24 18:08:01
【问题描述】:
我正在我的计算机上运行 SQL Server Express 2017 实例。我正在尝试使用以下连接字符串连接到它:
"Driver=ODBC Driver 13 for SQL Server;Server=COMPUTERNAME\\SQLEXPRESS,1433;Database=databasename;Uid=testuser;Pwd=testpassword;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
我已成功使用这些连接手动连接到服务器,并使用 SQL Server Management Studio 进行 SQL Server 身份验证。
防火墙应该不是问题,因为它是本地托管的服务器,但无论如何我已经为入站和出站连接打开了端口 1433。
这种连接字符串格式过去曾与托管在 Azure 上的数据库一起使用(我再也负担不起了)。
错误信息:
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.\r\n (10061) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 13 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. (10061)')
还有什么建议吗?
【问题讨论】:
-
SQLEXPRESS 实例几乎从不监听 1433 端口。试试
SERVER=(local)\SQLEXPRESS(省略端口号)看看效果是否更好。 -
@GordThompson (local) 被替换为 PC 名称或实际上是
local? -
字面意思是
(local)。你也可以使用.\SQLEXPRESS
标签: python sql-server odbc pyodbc