我正在尝试连接到Microsoft Azure sql Server数据库.
这是我试图连接的方式:
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"))
pyodbc.Error: ('01000',"[01000] [unixODBC][Driver Manager]Can't open lib 'sql Server' : file not found (0) (sqlDriverConnect)")
无法想象为什么会这样,有什么想法吗?
解决方法
我还建议您安装ODBC驱动程序,然后尝试使用pyodbc.我假设你在Ubuntu 15.04机器上.
要安装ODBC驱动程序,请遵循以下说明:
sudo su wget https://gallery.technet.microsoft.com/ODBC-Driver-13-for-Ubuntu-b87369f0/file/154097/2/installodbc.sh sh installodbc.sh
完成后,使用pip安装pyodbc并尝试以下脚本:
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()
让我知道这是怎么回事.
干杯,遇见