在Ubuntu上通过pyODBC连接到Microsoft SQL Server

时间:2022-01-30 01:40:56

Am having an issue connecting to a Microsoft SQL Server instance from pyODBC within an Ubuntu (12.10) machine.

在Ubuntu(12.10)计算机内从pyODBC连接到Microsoft SQL Server实例时出现问题。

The error I am getting back is:

我得到的错误是:

pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data Source name not found, and no default driver specified (0) (SQLDriverConnect)')

The connection string am using for pyodbc is:

用于pyodbc的连接字符串是:

self.corpus_cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER=UKEDN-06880;DATABASE=db1;UID=user;PWD=pass')

This seems to work fine from pyODBC within Windows (just need to change the DRIVER to 'SQL Server' instead of 'FreeTDS'), and it work fine when I try to connect from the Ubuntu machine using the tsql Tool from the terminal, with the following command:

这似乎可以在Windows中的pyODBC中正常工作(只需要将DRIVER更改为'SQL Server'而不是'FreeTDS'),当我尝试使用终端上的tsql工具从Ubuntu机器连接时,它工作正常,以下命令:

tsql -S UKEDN-06880 -p 1433 -U user -P pass

I can select any table with no issues, it just doesn't seem to work from within pyODBC.

我可以选择任何没有问题的表,它似乎没有在pyODBC内工作。

Any help or advice will be much appreciated, my Linux skills are uber weak and am totally stuck, although since it works from tsql I get the feeling that am very close!

任何帮助或建议将不胜感激,我的Linux技能非常弱,我完全陷入困境,虽然它从tsql工作,我感觉非常接近!

2 个解决方案

#1


9  

It looks like you have gotten freeTDS to work correctly since you can use tsql. Have you tried to connect with isql?

看起来你已经使freeTDS正常工作,因为你可以使用tsql。你试过连接isql吗?

Look at this howto for a detailed walk through. The part I think you need is in setting up unixodbc a little ways down the page.

看看这个如何进行详细的演练。我认为你需要的部分是在页面上设置unixodbc。

#2


2  

first stape $ sudo apt-get install libmdbodbc1

第一个stape $ sudo apt-get install libmdbodbc1

edit the file /etc/odbcinst.ini like this

像这样编辑文件/etc/odbcinst.ini

[Microsoft Access Driver (*.mdb)]
Description = Microsoft Access Driver (*.mdb)
Driver      = /path/to/file/libmdbodbc.so
Setup       = /path/to/file/libtdsS.so
CPTimeout   = 
CPReuse     = 

And the file /etc/odbc.ini

和文件/etc/odbc.ini

[Microsoft Access Driver (*.mdb)]
Description         = SQL Server
Driver              = Microsoft Access Driver (*.mdb)
Trace               = No
TraceFile           = /tmp/mssodbc.log

#1


9  

It looks like you have gotten freeTDS to work correctly since you can use tsql. Have you tried to connect with isql?

看起来你已经使freeTDS正常工作,因为你可以使用tsql。你试过连接isql吗?

Look at this howto for a detailed walk through. The part I think you need is in setting up unixodbc a little ways down the page.

看看这个如何进行详细的演练。我认为你需要的部分是在页面上设置unixodbc。

#2


2  

first stape $ sudo apt-get install libmdbodbc1

第一个stape $ sudo apt-get install libmdbodbc1

edit the file /etc/odbcinst.ini like this

像这样编辑文件/etc/odbcinst.ini

[Microsoft Access Driver (*.mdb)]
Description = Microsoft Access Driver (*.mdb)
Driver      = /path/to/file/libmdbodbc.so
Setup       = /path/to/file/libtdsS.so
CPTimeout   = 
CPReuse     = 

And the file /etc/odbc.ini

和文件/etc/odbc.ini

[Microsoft Access Driver (*.mdb)]
Description         = SQL Server
Driver              = Microsoft Access Driver (*.mdb)
Trace               = No
TraceFile           = /tmp/mssodbc.log