1

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
6
  • 1
    SQL Server 2005, 2008 and 2008 R2 are all out of even extended support - don't use them anymore! Upgrade to a more recent version ASAP!
    – marc_s
    Commented Jun 21, 2020 at 11:27
  • 1
    Upgrading Express is free too, there's no excuse to be using technology that has been unsupported for 5+ years.
    – Thom A
    Commented Jun 21, 2020 at 11:28
  • @marc_s other software work with sql server work and can login to specific instance !!!
    – Javad
    Commented Jun 21, 2020 at 11:32
  • @Larnu i don't know why not work it , other software can login to sql server without problem
    – Javad
    Commented Jun 21, 2020 at 11:33
  • Neither of those comments tell us why you're using software that has been completely unsupported for 5 years though.
    – Thom A
    Commented Jun 21, 2020 at 11:51

1 Answer 1

1

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.