Have you installed the driver?
Data source name not found and no default driver specified
Dear everyone
I am trying to connect to an mssql server via Python using the pyodbc package. I have the following code
1. import pyodbc
2.
3. cnxn_str = ("Driver={SQL Server Native Client 11.0};"
4. "Server=MyServer;"
5. "Database=Test;"
6. "Trusted_Connection=yes;")
7.
8. cnxn = pyodbc.connect(cnxn_str)
I keep getting the error message "Data source name not found and no default driver specified" from line 8. I have tried using "SQL Server Native Client 11.0" as well as "odbc driver 18 for sql server" as a Driver if someone is curious.
The full Traceback is:
Traceback (most recent call last):
File "d:\Database\test.py", line 8, in <module>
cnxn = pyodbc.connect(cnxn_str)
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
PS D:\Database>
Can anyone guide me through how to connect succesfully and execute queries on a MSSQL with Python using the pyodbc package? I have read the documentation and can't really seem to see why I keep getting the above error. Do I need to download something external or configure my MSSQL in a different way? Thanks in advance.
Windows for business | Windows Client for IT Pros | User experience | Other
SQL Server | Other
2 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
2023-03-30T15:24:35.83+00:00 -
Seeya Xi-MSFT 16,586 Reputation points
2023-03-31T06:22:41.18+00:00 Hi @TheExecutable ,
Please refer to this similar thread:
You can check the DSN 64-bit with ODBC Data Source Administrator if you are using a 64-bit version of Windows( If you are on 32-bit Windows, select 32-bit).
Best regards,
Seeya
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".