Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyodbc - "Data source name not found, and no default driver specified"

I have trouble getting pyodbc work. I have unixodbc , unixodbc-dev, odbc-postgresql, pyodbc packages installed on my Linux Mint 14. I am losing hope to find solution on my own, any help appreciated. See details below:

Running:

>>> import pyodbc >>> conn = pyodbc.connect("DRIVER={PostgreSQL};SERVER=localhost;DATABASE=test;USER=openerp;OPTION=3;") 

Gives me:

>>> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)') 

# odbcinst -j gives:

unixODBC 2.2.14 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /home/atman/.odbc.ini SQLULEN Size.......: 4 SQLLEN Size........: 4 SQLSETPOSIROW Size.: 2 

Which makes me think there is a unixodbc configuration problem. Here are my unixodbc config file contents:

File /etc/odbcinst.ini:

[PostgreSQL ANSI] Description     = PostgreSQL ODBC driver (ANSI version) Driver      = psqlodbca.so Setup       = libodbcpsqlS.so Debug       = 0 CommLog     = 1 UsageCount      = 2  [PostgreSQL Unicode] Description     = PostgreSQL ODBC driver (Unicode version) Driver      = psqlodbcw.so Setup       = libodbcpsqlS.so Debug       = 0 CommLog     = 1 UsageCount      = 2 

File /etc/odbc.ini :

[PostgreSQL test] Description         = PostgreSQL  Driver              = PostgreSQL ANSI Trace               = No TraceFile           = /tmp/psqlodbc.log Database            = template1 Servername          = localhost UserName            = Password            = Port                = ReadOnly            = Yes RowVersioning       = No ShowSystemTables    = No ShowOidColumn       = No FakeOidIndex        = No ConnSettings        = 

File ~/.odbc.ini:

[DEFAULT] Driver = PostgreSQL  [PostgreSQL] Description         = Test to Postgres Driver              = PostgreSQL Trace               = Yes TraceFile           = sql.log Database            = nick Servername          = localhost UserName            = Password            = Port                = 5432 Protocol            = 6.4 ReadOnly            = No RowVersioning       = No ShowSystemTables    = No ShowOidColumn       = No FakeOidIndex        = No ConnSettings        = 
like image 489
atman Avatar asked Apr 29 '13 13:04

atman


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.


1 Answers

I believe the answer to your problem is that in your ~/.odbc.ini file you are saying to use driver PostgreSQL - but you have not defined that driver in your /etc/odbcinst.ini file. Try changing PostgreSQL to PostgreSQL ANSI or PostgreSQL Unicode (both of which are defined in /etc/odbcinst.ini).

like image 103
Benny Hill Avatar answered Sep 22 '22 01:09

Benny Hill