0
votes

I am trying to use pyodbc with sql server. However I am getting the following error:

InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)').

This is my connection code

odbc_conn_str= 'DRIVER= {Microsoft Access Driver (*.mdb)}; DBQ=%s' %db_file
conn= pyodbc.connect(odbc_conn_str)
1
Are you running 64-bit Python?Gord Thompson

1 Answers

0
votes

You are saying you are trying to connect to an SQL server but using a Microsoft Access Driver. Only use a Microsoft Access Driver if connecting to an Access Database/File.

Try the following, this is why I use to connect to a Microsoft SQL Server: sql_connection = pyodbc.connect('DRIVER={SQL Server};SERVER=IPADDRESS\SQLSERVERINSTANCE;DATABASE=DBNAME;UID=USERNAME;PWD=PASSWORD;Trusted_Connection=no;')

Microsoft have a doc on setting up pyodbc for Microsoft SQL Server: https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-pyodbc?view=sql-server-ver15