Linux python3 - Can't open lib 'SQL Server'
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.
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
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()
Let me know how that goes.
Cheers,
Meet
Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?
Running:
odbcinst -j
It yielded:
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /Users/emehex/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Instead of copying the files to the /etc/
directory (not sure why unixODBC thought they were there) I created a symbolic link to each file:
sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
This solved the problem.
Related Topics
Cross Join Without Duplicate Combinations
Oracle: Combine Multiple Results in a Subquery into a Single Comma-Separated Value
Regular Expression in Postgresql Like Clause
How to Make a Parametrized SQL Query on Classic Asp
Conditional Logic in Postdeployment.SQL Script Using SQLcmd
Must Declare the Scalar Variable
How to Execute an in Lookup in SQL Using Golang
Select Rows Where Column Value Has Changed
Hamming Distance on Binary Strings in SQL
Access - Compare Two Tables and Update or Insert Data in First Table
How to Fill Date Gaps in MySQL
Ora - 00933 Confusion with Inner Join and "As"
Any Way to Achieve Fulltext-Like Search on Innodb
Why Using a Udf in a SQL Query Leads to Cartesian Product
Generating Random Strings with T-Sql
How to Get Export Output in "Real" CSV Format in SQL Server Management Studio