有关unixODBC:Data source name not found, and no default driver specified的问题
还是昨天测试postgresql的有关Mirroring Controller的功能时出的问题(真TM是个坑)。
首先说下环境:
-
操作系统平台:RHEL6 x86_64
-
unixODBC版本:2.3.1
在使用unixODBC连接postgresql数据库的时候报错:
The driver reported the following diagnostics whilst running [SQLDriverConnect]
IM002:1:140733193388032:[unixODBC][Driver Manager]Data source name not found, and no default driver specified
Failed to connect
非常费解,查看网上的资料,弄了好一会才搞清楚。
首先根据错误消息搜索:
http://www.easysoft.com/developer/interfaces/odbc/sqlstate_status_return_codes.html
查明错误原因是ODBC数据库连接字符串没找到或者ODBC默认的驱动没有装。
发生错误时我的odbc.ini配置如下
-
[DB3]
-
Description = SymfowareServer
-
Driver = SymfoV12
-
Database = postgres
-
Servername = {primary,standby}
-
UserName = postgres
-
Password = postgres
-
Port = {26500,26501}
-
TargetServer = primary
-
SSLMode = verify-full
-
SSLServerCertCN=Common
-
ReadOnly = 0
-
-
[DB4]
-
Description = SymfowareServer
-
Driver = SymfoV12
-
Database = postgres
-
Servername = {standby,primary}
-
UserName = postgres
-
Password = postgres
-
Port = {26501,26500}
-
TargetServer = prefer_standby
-
SSLMode = verify-full
-
SSLServerCertCN=Common
-
ReadOnly = 0
odbcinst.ini配置如下:
-
[SymfoV12]
-
Description = ODBC for Symfoware Open V12.1.1
-
#Driver = /opt/symfoclient64/odbc/lib/psqlodbcw.so
-
# Setup = /usr/lib/libodbcpsqlS.so
-
Driver64 = /opt/symfoclient64/odbc/lib/psqlodbcw.so
-
Setup64 = /usr/lib64/libodbcpsqlS.so
-
FileUsage = 1
-
Threading = 2
unixODBC自带测试链接的命令
isql -v DB3
运行后,提示:
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
我先检查了下postgresql的驱动psqlodbc有没有安装...
居然没有安装!!!
于是安装上psqlodbc,此时最新的版本是psqlodbc-09.05.0400
-
tar zxvf psqlodbc-09.05.0400.tar.gz
-
cd psqlodbc-09.05.0400
-
./configure --with-unixodbc --with-libpq=/usr/local/pgsql
-
make
-
make install
安装成功,默认驱动放在/usr/local/lib/psqlodbcw.so下。
安装完以后,继续测试,居然还报错!!!!
继续百度,参考下文:
http://china.ygw.blog.163.com/blog/static/687197462013418101335419/
找了半天,终于发现问题,原来是环境变量未正确配置,系统找不到配置文件。本来之前是正确的,后来我修改了unixODBC的目录名称,导致找不到了,通过执行odbcinst -j命令可以查看当前配置信息情况,以确认相关配置信息的路径是否正确。
我的配置如下:
-
unixODBC 2.3.1
-
DRIVERS............: /usr/local/etc/odbcinst.ini
-
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
-
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
-
USER DATA SOURCES..: /root/.odbc.ini
-
SQLULEN Size.......: 8
-
SQLLEN Size........: 8
-
SQLSETPOSIROW Size.: 8
重新配置ODBCINI及ODBCSYSINI两个环境变量即可。
其中,ODBCINI设置为odbc.ini的文件路径全名,ODBCSYSINI配置为配置文件路径,参照我的配置内容如下:
-
export ODBCINI=/usr/local/etc/odbc.ini
-
export ODBCSYSINI=/usr/local/etc
再次使用isql测试:
isql -v DB3
一切OK。
转载于:https://www.cnblogs.com/flying-tiger/p/5950600.html