Reputation: 4159
Getting the "[unixODBC][Driver Manager]Data source name not found, and no default driver specified"
despite /etc/odbc.ini
having the DSN referenced in the connection string. Why would this be happening and what can be done?
Trying to set up pyodbc
for connecting to MSSQLServer using the docs (centos 7). Yet, when trying to actually connect to the database,
import pyodbc
# setup db connection
server = 'myserver'
database = 'mydb'
username = 'myusername'
password = 'mypassword'
cnxn_str = 'DSN=MyMSSQLServer;DATABASE='+database+'UID='+username+'PWD='+password+'MultipleActiveResultSets=True;'
cnxn = pyodbc.connect(cnxn_str)
getting error "[unixODBC][Driver Manager]Data source name not found, and no default driver specified"
, even though when running:
[mapr@mnode01 ~]$ cat /etc/odbc.ini
[MyMSSQLServer] Driver=ODBC Driver 13 for SQL Server
Description=My MS SQL Server
Trace=No
Server=<now using my sql server ip>
I can see that the DSN that I referenced in the python code is recorded in the /etc/odbc.ini
file. Does anyone know what could be going on here? Thanks.
Note: I initially ran the pyodbc setup exactly as specified in the docs, but later re-did this step to use the ip address of the sql server I wanted to connect to:
vi /home/user/odbcadd.txt
[MyMSSQLServer] Driver = ODBC Driver 13 for SQL Server
Description = My MS SQL Server
Trace = No
Server = <my sql server ip>
and just re-ran the write to odbc.ini
:
sudo odbcinst -i -s -f /home/user/odbcadd.txt -l
Upvotes: 2
Views: 16320
Reputation: 4159
The solution commented by user Gord Thompson solved my problem. The ~/odbcadd.txt
file that I was using to fill the /etc/odbc.ini
file needed to have the 'Driver=' line on a separate line from the DSN to look like:
[mapr@mnode01 ~]$ cat /etc/odbc.ini
[MyMSSQLServer]
Driver=ODBC Driver 13 for SQL Server
Description=My MS SQL Server
Trace=No
Server=172.18.4.38
Upvotes: 8