Skip to content

Instantly share code, notes, and snippets.

@zergioz
Created July 7, 2020 20:25
Show Gist options
  • Save zergioz/6402aa2b8850a2f6ad431e7a8b7e52c6 to your computer and use it in GitHub Desktop.
Save zergioz/6402aa2b8850a2f6ad431e7a8b7e52c6 to your computer and use it in GitHub Desktop.
# Works on windows, but a differentent set of drivers are needed for linux "FreeTDSs"
# Change file odbcinst.ini by adding
# [FreeTDS]
# Description=v0.63 with protocol v8.0
# Driver=/usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
# UsageCount=2
# In code change "ODBC Driver 17 for SQL Server" for "DRIVER=FreeTDS"
import pyodbc
server = 'MYIP'
database = 'MYDB'
username = 'MYUSERNAME'
password = 'MYPASSWORD'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
#Sample test
cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment