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.