问题描述
我在Centos 7 Linux计算机上,尝试通过pyodbc连接到SQL数据库。我了解到您需要设置DSN,并通过安装freetds驱动程序并执行以下操作来做到这一点:
I am on a Centos 7 Linux machine trying to connect to an SQL database through pyodbc. I learned that you need to setup the DSN and you do that by installing the freetds driver and doing something like:
import pyodbc
cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER=example;DATABASE=TEST;')
不幸的是,当我这样做时,我收到一条错误消息,指出找不到驱动程序FreeTDS。我已经跑了:
Unfortunately when I do that I get an error saying the driver FreeTDS can't be found. I have ran:
$ ./configure
$ make
$ make install
它似乎已经安装了,但出现了同样的错误。有人可以给我发送工作示例的链接吗?
It seemed to have installed it but I get the same error. Can someone please send me a link to a working example
推荐答案
如果要从源代码编译FreeTDS,它将安装到/ usr / local / freetds,IIRC。您还可以通过 yum
在CentOS上进行安装,并且还需要unixODBC。基本上,FreeTDS将SQL Server桥接到unixODBC,将pyodbc桥接unixODBC到Python。
If you're compiling FreeTDS from source, it'll install to /usr/local/freetds, IIRC. You can also install via yum
on CentOS, and you'll need unixODBC as well. Basically, FreeTDS bridges SQL Server to unixODBC, and pyodbc bridges unixODBC to Python.
以下是FreeTDS,unixODBC和朋友设置的示例:
Here's an example set up with FreeTDS, unixODBC, and friends:
freetds.conf:
freetds.conf:
[server]
host = server.com
port = 1433
tds version = 7.3
odbc.ini:
[server]
Driver = FreeTDS
Server = server.com
Port = 1433
TDS_Version = 7.3
odbcinst.ini:
odbcinst.ini:
[FreeTDS]
Description = FreeTDS with Protocol up to 7.3
Driver = /usr/lib64/libtdsodbc.so.0
Driver =
的位置可能有所不同,具体取决于您的FreeTDS发行版-如果您是从源代码编译的,很可能是 /usr/local/freetds/lib/libtdsodbc.so
。
The Driver =
location may differ above, depending on your distro of FreeTDS - if you compiled from source, most likely, /usr/local/freetds/lib/libtdsodbc.so
.
pyodbc连接,免费使用DSN:
pyodbc connect, DSN free:
DRIVER={FreeTDS};SERVER=server.com;PORT=1433;DATABASE=dbname;UID=dbuser;PWD=dbpassword;TDS_Version=7.3;
一些注意事项:
- 您必须更新TDS版本以匹配您正在运行的SQL Server版本和您正在运行的免费TDS版本。 0.95版本支持TDS版本7.3。
- TDS版本7.3将与MS SQL Server 2008及更高版本一起使用。
- 将TDS版本7.2用于MS SQL Server 2005。
更多信息,请参见此处:
See here for more:
祝你好运。
这篇关于Pyodbc找不到FreeTDS驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!