Pyodbc: Login timeout expired

0

I am trying to connect to MS SQL Server using pyodbc on local system and on connect to instance i get error:

[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)')

My SQL Server is Express 2005 and try with drivers:

  • {ODBC Driver 13 for SQL Server}
  • {ODBC Driver 17 for SQL Server}
  • {SQL Native Client}

I test in sqlcmd with this command:

C:\Users\Moein>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.

My Code :

import pyodbc

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

More:

  • Test -l 600 switch for login timeout more in sqlcmd > not answer recived
  • Test computername\instance and 127.0.0.1\instance > Not changed
  • Try full reinstall sql server on local > noting changed things
sql-server
python-3.x
pyodbc
asked on Stack Overflow Jun 21, 2020 by Javad

1 Answer

0

i found my problem

i use this connection string with pipe mode:

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:\\.\pipe\MSSQL$testsv\sql\query',autocommit=True)
answered on Stack Overflow Jun 22, 2020 by Javad

User contributions licensed under CC BY-SA 3.0