title: "[unixODBC][Driver Manager]Data source name not found, and no default driver specified" despite /etc/odbc.ini having the DSN
body: <p>Getting the <code>"[unixODBC][Driver Manager]Data source name not found, and no default driver specified"</code> despite <code>/etc/odbc.ini</code> having the DSN referenced in the connection string. Why would this be happening and what can be done?</p>
  
  <p>Trying to set up <code>pyodbc</code> for connecting to MSSQLServer using the <a href="https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7" rel="nofollow noreferrer">docs (centos 7)</a>. Yet, when trying to actually connect to the database, </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>getting error <code>"[unixODBC][Driver Manager]Data source name not found, and no default driver specified"</code>, even though when running:</p>
  
  <pre><code>[mapr@mnode01 ~]$ cat /etc/odbc.ini
  [MyMSSQLServer] Driver=ODBC Driver 13 for SQL Server
  Description=My MS SQL Server
  Trace=No
  Server=&lt;now using my sql server ip&gt;
  </code></pre>
  
  <p>I can see that the DSN that I referenced in the python code is recorded in the <code>/etc/odbc.ini</code> file. Does anyone know what could be going on here? Thanks.</p>
  
  <p><strong>Note</strong>: I initially ran the pyodbc setup exactly as specified in the <a href="https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7#prepare-a-temp-file-for-defining-the-dsn-to-your-database-server" rel="nofollow noreferrer">docs</a>, but later re-did <a href="https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7#prepare-a-temp-file-for-defining-the-dsn-to-your-database-server" rel="nofollow noreferrer">this</a> step to use the ip address of the sql server I wanted to connect to:</p>
  
  <pre><code>vi /home/user/odbcadd.txt
  
  [MyMSSQLServer] Driver = ODBC Driver 13 for SQL Server
  
  Description = My MS SQL Server
  
  Trace = No
  
  Server = &lt;my sql server ip&gt;
  </code></pre>
  
  <p>and just re-ran the write to <code>odbc.ini</code>:</p>
  
  <pre><code>sudo odbcinst -i -s -f /home/user/odbcadd.txt -l
  </code></pre>