无法为 Raspbian 10 上的 SQL 服务器获取 ODBC 驱动程序 17 (Buster)
Unable to get ODBC Driver 17 for SQL Server on Raspbian 10 (Buster)
我正在尝试在我的 raspberry pi 上安装 "ODBC Driver 17 for SQL Server" 但没有成功。
1 这是我试过的
FROM arm32v7/python:3
RUN apt-get update
1. Install dependencies for PyODBC and tds
RUN apt-get install -y tdsodbc unixodbc-dev
RUN apt install unixodbc-bin -y
RUN apt-get clean -y
2. Edit /etc/odbcinst.ini
RUN echo "[FreeTDS]\n\
Description = FreeTDS unixODBC Driver\n\
Driver = /usr/lib/arm-linux-gnueabi/odbc/libtdsodbc.so\n\
Setup = /usr/lib/arm-linux-gnueabi/odbc/libtdsS.so" >> /etc/odbcinst.ini
3. Install requirements (contains pyodbc)
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
Copy and run my app
COPY . .
CMD [ "python", "app.py"]
我的代码:
import pyodbc
def inserare(operator,loc_munca,comanda,stare,data,ora,bucati):
conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.\SQLEXPRESS;DATABASE=database;UID=pi;PWD=pass')
cursor = conn.cursor()
cursor.execute("insert into Pontaj values (?,?,?,?,?,?,?)",operator,loc_munca,comanda,stare,data,ora,bucati)
cursor.commit()
cursor.close()
来自 python 的错误 shell
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib >'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
终端错误
sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package tdsodbc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Unable to locate package freetds-dev
E: Unable to locate package freetds-bin
E: Package 'tdsodbc' has no installation candidate
我通过修改 /etc 上的 odbc.ini 和 odbcinst.in 设法解决了这个问题。
修改这些文件后,我能够连接到数据库。
我认为 ODBC 17 是空白的,这就是问题所在。
odbc.ini
Driver = FreeTDS
Description = My Test Server
Trace = No Server
Name = mssql
Port = port
instance = ip\SQLEXPRESS
Database = yourdatabase
TDS_Version = 4.2
odbcinst.in我
Description=FreeTDS
Driver v0.91
Driver=/usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup=/usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
fileusage=1
dontdlclose=1
UsageCount=1
我正在尝试在我的 raspberry pi 上安装 "ODBC Driver 17 for SQL Server" 但没有成功。
1 这是我试过的
FROM arm32v7/python:3
RUN apt-get update
1. Install dependencies for PyODBC and tds
RUN apt-get install -y tdsodbc unixodbc-dev
RUN apt install unixodbc-bin -y
RUN apt-get clean -y
2. Edit /etc/odbcinst.ini
RUN echo "[FreeTDS]\n\
Description = FreeTDS unixODBC Driver\n\
Driver = /usr/lib/arm-linux-gnueabi/odbc/libtdsodbc.so\n\
Setup = /usr/lib/arm-linux-gnueabi/odbc/libtdsS.so" >> /etc/odbcinst.ini
3. Install requirements (contains pyodbc)
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
Copy and run my app
COPY . .
CMD [ "python", "app.py"]
我的代码:
import pyodbc
def inserare(operator,loc_munca,comanda,stare,data,ora,bucati):
conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.\SQLEXPRESS;DATABASE=database;UID=pi;PWD=pass')
cursor = conn.cursor()
cursor.execute("insert into Pontaj values (?,?,?,?,?,?,?)",operator,loc_munca,comanda,stare,data,ora,bucati)
cursor.commit()
cursor.close()
来自 python 的错误 shell
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib >'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
终端错误
sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc Reading package lists... Done Building dependency tree
Reading state information... Done Package tdsodbc is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another sourceE: Unable to locate package freetds-dev
E: Unable to locate package freetds-bin
E: Package 'tdsodbc' has no installation candidate
我通过修改 /etc 上的 odbc.ini 和 odbcinst.in 设法解决了这个问题。 修改这些文件后,我能够连接到数据库。 我认为 ODBC 17 是空白的,这就是问题所在。
odbc.ini
Driver = FreeTDS
Description = My Test Server
Trace = No Server
Name = mssql
Port = port
instance = ip\SQLEXPRESS
Database = yourdatabase
TDS_Version = 4.2
odbcinst.in我
Description=FreeTDS
Driver v0.91
Driver=/usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup=/usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
fileusage=1
dontdlclose=1
UsageCount=1