-
-
Save si-software-lab/3de08367ab18c8604c092442489566b8 to your computer and use it in GitHub Desktop.
Revisions
-
rduplain revised this gist
Oct 17, 2011 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ *Goal:* Connect to MSSQL using FreeTDS / ODBC in Python. Host: Ubuntu 11.10 x86_64 Install: sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc pip install pyodbc sqlalchemy In /etc/odbcinst.ini: -
rduplain created this gist
Oct 17, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ *Goal:* Connect to MSSQL using FreeTDS / ODBC in Python. Install: sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc pip install pyodbc In /etc/odbcinst.ini: [FreeTDS] Description=FreeTDS Driver Driver=/usr/lib/odbc/libtdsodbc.so Setup=/usr/lib/odbc/libtdsS.so This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ "Proof connection at pyodbc level." # Test pyodbc connection. Result is 42. # Note parameters in connection string, <PARAMETER>. import pyodbc conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;') cursor = conn.cursor() for row in cursor.execute('select 6 * 7 as [Result];'): print row.Result This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ "Proof connection at SQLAlchemy level, on top of pyodbc." # Test SQLAlchemy connection. Result is 42. # Note parameters in connection string, <PARAMETER>. import urllib from sqlalchemy import create_engine engine = create_engine('mssql+pyodbc:///?odbc_connect=' + urllib.quote_plus('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;') ) for row in engine.execute('select 6 * 7 as [Result];'): print row.Result