Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYODBC--Data source name not found and no default driver specified

Tags:

python

sql

pyodbc

import pyodbc connection = pyodbc.connect('Driver = {SQL Server};Server=SIWSQL43A\SIMSSPROD43A;'                             'Database=CSM_reporting;Trusted_Connection=yes;') 

Error:

connection = pyodbc.connect('Driver = {SQL Server};Server=SIWSQL43A\SIMSSPROD43A;'     pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') 
like image 932
user8560985 Avatar asked Sep 05 '17 01:09

user8560985


People also ask

How do I fix data source name not found and no default driver specified?

You can check the drivers which are installed on your system by going to the ODBC Data Source Administrator. To open it, press ⊞ Win + R , and type in: odbcad32.exe . Then check the tab Drivers for installed drivers. The Name column indicates the exact name you should use in your connection string or DSN.

What driver do I use for Pyodbc?

pyODBC uses the Microsoft ODBC driver for SQL Server.


2 Answers

Do not put a space after the Driver keyword in the connection string.

This fails on Windows ...

conn_str = (     r'DRIVER = {SQL Server};'     r'SERVER=(local)\SQLEXPRESS;'     r'DATABASE=myDb;'     r'Trusted_Connection=yes;' ) cnxn = pyodbc.connect(conn_str) 

... but this works:

conn_str = (     r'DRIVER={SQL Server};'     r'SERVER=(local)\SQLEXPRESS;'     r'DATABASE=myDb;'     r'Trusted_Connection=yes;' ) cnxn = pyodbc.connect(conn_str) 
like image 111
Gord Thompson Avatar answered Sep 24 '22 19:09

Gord Thompson


I've met same problem and fixed it changing connection string like below. Write

'DRIVER={ODBC Driver 13 for SQL Server}' 

instead of

'DRIVER={SQL Server}' 
like image 29
Mil Avatar answered Sep 24 '22 19:09

Mil