有没有人有使用pyodbc通过Linux连接(AWS托管)Microsoft SQL Server的经验?
这是我的剧本:
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=myserver;PORT=1433;DATABASE=action_plan_db;UID=myuserid;PWD=mypassword;TDS_Version=7.0')
我收到错误:
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)'
我已经看到建议将unixODBC设置为使用FreeTSD&添加一个涉及编辑两个文件的数据源:“drivers”和“system data source”(分别为/etc/odbcinst.ini和/etc/odbc.ini)。但是,当我打开它们时,它们是空白的。
答案 0 :(得分:1)
你在开发什么Linux发行版?
这是Python + RHEL的教程:https://www.microsoft.com/en-us/sql-server/developer-get-started/python-rhel
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -ivh epel-release-latest-7.noarch.rpm
sudo yum update
sudo yum install python python-pip python-wheel python-devel
sudo yum group install "Development tools"
sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-tools.repo
exit
sudo yum install msodbcsql
sudo yum install unixODBC-utf16-devel
pip install pyodbc