I am using pyodbc to retrieve data from MSSQL and this is the code I am using:
import pyodbc
server = 'XXXXXXXXX\DEV,43853'
#server = 'XXXXXXXXX\DEV'
#Also used second server statement and got same error.
database = 'SandBox'
username = 'Username'
password = 'password'
driver = '{SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
#cnxn = pyodbc.connect('DRIVER='+driver+';PORT=43853;SERVER='+server+';PORT=43853;DATABASE='+database+';UID='+username+';PWD='+ password)
#Also Used cnxn second statement and got the same error
cursor = cnxn.cursor()
cursor.execute("select * from fieldscreenscheme ")
row = cursor.fetchone()
if row:
print row
This is the error massage I got:
Traceback (most recent call last):
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Specified SQL server not found. (6) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (11001)')
I installed the ODBC driver. The created the SYSTEM DSN and when it completes test successfully, but the python code does not work. Any recommendation how to solve the error?
Microsoft Documentation: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-connect-query-python
Recent Comments