Verifique os arquivos /etc/odbcinst.ini, /etc/odbc.ini, ~ / .odbc.ini e $ ODBCINI para ver quais direitos são atribuídos. Eu acredito que o usuário que está executando o comando pode não ter direitos sobre um desses arquivos, ou pode até não ter a fonte de dados definida se ele foi criado sob um usuário diferente.
Extraído de Mensagens de erro comuns e O que é um odbc.ini e o que eu coloco nele? Ainda mais, verifique o /etc/odbc.ini e ~ / .odbc.ini do usuário ao qual você adicionou o DSN, além do usuário que você está executando. Se estes são os mesmos, você só precisa fazer isso uma vez.
Mensagens de erro comuns
[iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded, SQLSTATE=IM002
There are several reasons why this message could occur. The best solution is to trace through what's happening: your application has been linked against libiodbc, which has tried to find an odbc.ini file one way or another - either through the ODBCINI environment variable or the fall-back paths (typically /etc/odbc.ini, depending on how it was compiled). You should check that such a file exists in a suitable location, and that it is accessible (particularly if your application runs with different user privileges - such as apache/php running as a www-data user).
Additionally, it could be that iODBC has found a suitable odbc.ini file, but none of the file(s) found contain the DSN you've requested. Check the syntax of your request - is the ODBC connect-string correct, and does the DSN you're requesting exist? See also the section of this FAQ, above, entitled 'What's an odbc.ini and what do I put in it?'.
O que é um odbc.ini
An odbc.ini is the main configuration file in which all your DSNs and much of the ODBC configuration parameters are stored. iODBC has a search-path for finding such a configuration file: first, the environment variable ODBCINI is inspected to see if it points at a suitable file, or ~/.odbc.ini (analagous to User DSNs on Windows) then /etc/odbc.ini ("system-wide") are fall-back locations.
The odbc.ini file comprises 3 parts: a set of ODBC options, a list of DSNs, and then the datasource definitions themselves, thus:
[ODBC Data Sources]
PostgreSQL native localhost = PostgreSQL native driver
PostgreSQL OpenLink localhost = PostgreSQL over OpenLink multi-tier
[PostgreSQL native localhost]
Driver = /usr/lib/postgresql/lib/libodbcpsql.so
Host = localhost
Server = localhost
ServerName = localhost
Database = tim
UserName = tim
UID = tim
Port = 5432
[PostgreSQL OpenLink localhost]
Description = PostgreSQL, over openlink MT
Driver = /opt/openlink/lib/oplodbc.so
ServerType = PostgreSQL95
Host = localhost
Database = tim
Username = tim
LastUser = tim
User = tim
FetchBufferSize = 99
[ODBC]
;Trace = 1
;TraceFile = /tmp/odbctrace.log ;Debug = 1
;DebugFile = /tmp/odbcdebug.log
The list of ODBC Data Sources correlate with the file odbcinst.ini (or environment variable ODBCINSTINI): for every value used as a description of the driver there should be a corresponding section in odbcinst.ini listing both the Driver and Setup library (to assist with graphical configuration using iodbcadm-gtk, and also used to display an input box in the event of insufficient options being presented at connection-time).
The list of attributes is driver-dependent, as the above shows: the native postgresql driver calls them different things from openlink multi-tier, so you have to check with your driver's documentation.
With iODBC, assuming you downloaded/installed/compiled it, you also have a GTK-based GUI for configuring your ODBC DSNs, too: run iodbcadm-gtk.