本文介绍了Linux python3-无法打开lib'SQL Server'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试连接到Microsoft Azure SQL服务器数据库.
I am trying to connect to an Microsoft Azure SQL server database.
这就是我尝试连接的方式:
This is how i am trying to connect:
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=%s' % (self.config.get("Sql", "DataSource")),
user= self.config.get("Sql", "UserId"),
password=self.config.get("Sql", "Password"),
database=self.config.get("Sql", "Catalog"))
执行此行时出现错误.错误:
I am getting an error while excuting this line. The error:
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")
不知道为什么会这样吗,知道吗?
Can't figure why this is happening, Any idea?
推荐答案
我还建议您安装ODBC驱动程序,然后尝试使用pyodbc.我假设您使用的是Ubuntu 15.04+计算机.
I also recommend you install the ODBC Driver and then try to use pyodbc. I am assuming you are on an Ubuntu 15.04+ machine.
要安装ODBC驱动程序,请按照以下说明进行操作:
To install the ODBC Driver follow the following instructions:
sudo su
wget https://gallery.technet.microsoft.com/ODBC-Driver-13-for-Ubuntu-b87369f0/file/154097/2/installodbc.sh
sh installodbc.sh
完成此操作后,请使用pip安装pyodbc并尝试以下脚本:
Once you do that, install pyodbc using pip and try the following script:
import pyodbc
server = 'tcp:myserver.database.windows.net'
database = 'mydb'
username = 'myusername'
password = 'mypassword'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
print row
row = cursor.fetchone()
让我知道怎么回事.
干杯,
见面
这篇关于Linux python3-无法打开lib'SQL Server'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!