10
因此,我很难让所有这三者协调一致地工作。我想我会列出所有的各种配置,以及测试代码,看看是否有一双新鲜的眼睛能够实现我的愚蠢。遇到UnixODBC,FreeTDS和PyODBC的困扰
我正在运行12.04 Unbuntu Server,我试图连接到MSSQL Server 2008并最终与PyODBC一起使用它。
然而,在
tsql -S T2 -U Foo -P Bar
的时候只是把我得到的
1>
2>
3>
4>
5>
6>
7>
8>
9>
10>
11>
等
无论如何,如果有人能够帮助(我将永远感激如果你能清除我的阴霾),这里是我目前的配置。
这是我/etc/odbc.ini
[ODBC Data Sources]
odbcname = MySQL
T2 = MSSQL
[odbcname]
Driver = /usr/lib/odbc/libmyodbc.so
Description = MyODBC 3.51 Driver DSN
SERVER = Foobar
PORT = 3306
USER = Foo
Password = Bar
Database = Foobar
OPTION = 3
SOCKET =
[T2]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
SERVER = FOOBAR
PORT = 1433
USER = Foo
Password = Bar
Database = Foobar
OPTION = 3
SOCKET =
[Default]
Driver = /usr/local/lib/libmyodbc3.so
Description = MyODBC 3.51 Driver DSN
SERVER = FOOBAR
PORT = 3306
USER = foo
Password = bar
Database = FOOBAR
OPTION = 3
SOCKET =
以下是我/etc/odbcinst.ini
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so
CPTimeout=
CPReuse=
FileUsage=1
以下是我freetds.conf
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
#text size = 64512
[T2]
host = FOOBAR
port = 1433
tds version = 7.0
client charset = UTF-8
text size = 20971520
[global]
# TDS protocol version
tds version = 7.0
而我的Python测试文件只是为了测量
import pyodbc
import sys
try:
#tempsystrends = pyodbc.connect('DRIVER=FreeTDS;SERVER=FOOBAR;PORT=1433;DATABASE=T2;UID=FOO;PWD=bar;TDS_Version=7.0;')
cursor = tempsystrends.cursor()
except pyodbc.Error as e:
print "Error: %s" % (e.args[1])
sys.exit(1)
哇。这也许是我在Stack Overflow上读过的最完整的答案。唯一改变的是在/etc/odbcinst.ini中更改64位的位置:/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so – philshem
@philshem - 谢谢,我很高兴它很有用! –
迄今为止最完整的答案! – digz6666