Pyodbc:登录超时已过期



我正在尝试在本地系统上使用 pyodbc 连接到 MS SQL Server,并在连接到实例时出现错误:

[2020-06-21 15:39:04.110750]: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].  (-1) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (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. (-1)')

我的SQL Server是Express 2005,并尝试使用驱动程序:

  • {ODBC Driver 13 for SQL Server}
  • {ODBC Driver 17 for SQL Server}
  • {SQL 本机客户端}

我用以下命令在sqlcmd中进行测试:

C:UsersMoein>sqlcmd -S '.Moein' -U 'sa' -P 'xxxx'
HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

我的代码 :

import pyodbc
conn = pyodbc.connect(f'DRIVER={SQL Native Client};SERVER=.Moein;DATABASE=Moein;UID=sa;PWD=xxxx',autocommit=True)
cursor = conn.cursor()

更多:

  • 在sqlcmd中测试-l 600交换机的登录超时更多>未应答
  • 测试computernameinstance127.0.0.1instance>未更改
  • 尝试在本地重新安装 sql 服务器>注意更改的内容

我发现了我的问题

我将这个连接字符串与管道模式一起使用:

conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};ServerName=Provider=SQLOLEDB.1;SERVER=.testsv;DATABASE=test;Persist Security Info=False;UID=sa;PWD=xxxxx;Data Source=np:\.pipeMSSQL$testsvsqlquery',autocommit=True)

最新更新