How configure freetds and unixodbc on Linux Ubuntu
In odbcinst.ini, you need to provide the driver name, not the DSN. Change:
[wsus]
to:
[FreeTDS]
You should also modify the TDS version, most likely to 7.3 (SQL Server 2008 - 2014), as mentioned above.
That should do this trick! Good luck.
Can't Install FreeTDS via Yum Package Manager
As adopted from Benny Hill's comment above, this is what got freetds installed for me:
rpm -ivh ftp://fr2.rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
cd /etc/yum.repos.d/
wget http://rpms.famillecollet.com/enterprise/remi.repo
yum install freetds
yum install freetds-devel
yum install --enablerepo=remi php-mssql
Adopted from https://gist.github.com/shf/2052432
How do I update FreeTDS driver in RHEL-like Docker image?
So apparently your Dockerfile already has the required commands to install pyodbc. Therefore your container should already have
- gcc-c++
- python3-devel
- unixODBC-devel
Now instead of installing freetds from EPEL (or wherever) your Dockerfile will need to perform the following (which uses the latest stable version of FreeTDS at the time of writing):
curl https://www.freetds.org/files/stable/freetds-1.2.18.tar.gz > freetds-1.2.18.tar.gz
tar -xvzf freetds-1.2.18.tar.gz
cd freetds-1.2.18/
./configure
make
sudo make install
echo "" | sudo tee -a /etc/odbcinst.ini > /dev/null
echo "[FreeTDS_1.2.18]" | sudo tee -a /etc/odbcinst.ini > /dev/null
echo "Driver=/usr/local/lib/libtdsodbc.so" | sudo tee -a /etc/odbcinst.ini > /dev/null
Then you should be able to create a pyodbc connection like so:
>>> import pyodbc
>>> cnxn = pyodbc.connect("DRIVER=FreeTDS_1.2.18;SERVER=192.168.0.179;PORT=49242;UID=sa;PWD=_whatever_;")
>>> print(cnxn.execute("SELECT @@VERSION").fetchval())
Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) - 14.0.2037.2 (X64)
Nov 2 2020 19:19:59
Copyright (C) 2017 Microsoft Corporation
Express Edition (64-bit) on Windows 8.1 Pro 6.3 (Build 9600: )
>>> print(cnxn.getinfo(pyodbc.SQL_DRIVER_NAME))
libtdsodbc.so
>>> print(cnxn.getinfo(pyodbc.SQL_DRIVER_VER))
01.02.0018
Related Topics
How to Update Identity Column in SQL Server
Convert Timestamp to Date in MySQL Query
Using an Alias in SQL Calculations
Select/Group by - Segments of Time (10 Seconds, 30 Seconds, etc)
Emulate MySQL Limit Clause in Microsoft SQL Server 2000
Identity Column Value Suddenly Jumps to 1001 in SQL Server
Sql: Find the Max Record Per Group
How to Find All Connected Subgraphs of an Undirected Graph
SQL Query to Pivot a Column Using Case When
Delete Duplicate Rows (Don't Delete All Duplicate)
Update a Column Value, Replacing Part of a String
How to Replace a String in a SQL Server Table Column
What MySQL Database Tables and Relationships Would Support a Q&A Survey With Conditional Questions
Reference Alias (Calculated in Select) in Where Clause
How to Find a "Gap" in Running Counter With Sql