pyodbc 不适用于 RedHat 5.4。尝试使用 unixODBC 和 FreeTDS 连接到 ms-sql 数据库服务器?
pyodbc not working on RedHat 5.4. Trying to connect to ms-sql database server using unixODBC and FreeTDS?
我在尝试使用 pyobdc 访问 ms-sql 数据库时遇到问题。
这是系统配置:
Python 2.7.11
pyodbc 3.0.7
RedHat 5.4 (Tikanga) 32 位系统
Microsoft SQL Server 2012(数据库服务器)
unixODBC 2.3.0
$tsql -C
输出:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
$odbcinst -j
输出:
unixODBC 2.3.0
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.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
$cat /usr/local/etc/odbcinst.ini
输出:
[ms-sql]
Description=TDS connection
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
FileUsage=1
UsageCount=1
$cat /usr/local/etc/odbc.ini
输出:
[sqlserverdatasource]
Driver = ms-sql
Description = ODBC connection via ms-sql
Trace = No
Server = >IP Addresss To Database server<
Port = >Port Number<
Database = >Database name<
$cat /etc/freetds.conf
输出:
[sql-server]
host = >IP Addresss To Database server<
port = >Port Number<
tds version = 8.0
给我错误的命令:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=>IP Addresss To Database server<; PORT=>Port Number<;DATABASE=Database name;UID=Database UID;PWD=DatabasePasswd;')
错误:
Traceback (most recent call last): File "<stdin>", line 1, in
<module> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver
Manager]Data source name not found, and no default driver specified
(0) (SQLDriverConnect)')
过去 3 天我一直在努力解决这个问题。但还没有运气。所以任何 help/suggestion 都会很有帮助。
我已经通过谷歌搜索了。
提前致谢:)
尝试这样的事情:
freetds.conf:
[sql-server]
host = sql-server.host.com
port = 1433
tds version = 7.2
odbc.ini:
[sql-server]
Driver = FreeTDS
Server = sql-server.host.com
Port = 1433
TDS_Version = 7.2
odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/local/lib/libtdsodbc.so
在Python中:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=sql-server.host.com;PORT=1433;DATABASE=Database name;UID=Database Username;PWD=DatabasePasswd;TDS_Version=7.2')
TDS 8.0 版不存在。 7.2 是 FreeTDS 0.91 中支持的最高版本。混淆解释见这里:http://www.freetds.org/userguide/choosingtdsprotocol.htm
如果仍有问题,请尝试使用 tsql
和 isql
分别测试连接堆栈的 FreeTDS 和 unixODBC 层。祝你好运!
我在尝试使用 pyobdc 访问 ms-sql 数据库时遇到问题。
这是系统配置: Python 2.7.11 pyodbc 3.0.7 RedHat 5.4 (Tikanga) 32 位系统 Microsoft SQL Server 2012(数据库服务器) unixODBC 2.3.0
$tsql -C
输出:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
$odbcinst -j
输出:
unixODBC 2.3.0
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.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
$cat /usr/local/etc/odbcinst.ini
输出:
[ms-sql]
Description=TDS connection
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
FileUsage=1
UsageCount=1
$cat /usr/local/etc/odbc.ini
输出:
[sqlserverdatasource]
Driver = ms-sql
Description = ODBC connection via ms-sql
Trace = No
Server = >IP Addresss To Database server<
Port = >Port Number<
Database = >Database name<
$cat /etc/freetds.conf
输出:
[sql-server]
host = >IP Addresss To Database server<
port = >Port Number<
tds version = 8.0
给我错误的命令:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=>IP Addresss To Database server<; PORT=>Port Number<;DATABASE=Database name;UID=Database UID;PWD=DatabasePasswd;')
错误:
Traceback (most recent call last): File "<stdin>", line 1, in
<module> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver
Manager]Data source name not found, and no default driver specified
(0) (SQLDriverConnect)')
过去 3 天我一直在努力解决这个问题。但还没有运气。所以任何 help/suggestion 都会很有帮助。 我已经通过谷歌搜索了。 提前致谢:)
尝试这样的事情:
freetds.conf:
[sql-server]
host = sql-server.host.com
port = 1433
tds version = 7.2
odbc.ini:
[sql-server]
Driver = FreeTDS
Server = sql-server.host.com
Port = 1433
TDS_Version = 7.2
odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/local/lib/libtdsodbc.so
在Python中:
connection = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=sql-server.host.com;PORT=1433;DATABASE=Database name;UID=Database Username;PWD=DatabasePasswd;TDS_Version=7.2')
TDS 8.0 版不存在。 7.2 是 FreeTDS 0.91 中支持的最高版本。混淆解释见这里:http://www.freetds.org/userguide/choosingtdsprotocol.htm
如果仍有问题,请尝试使用 tsql
和 isql
分别测试连接堆栈的 FreeTDS 和 unixODBC 层。祝你好运!