Use Python 2 and 3 Pyodbc and Sqlalchemy to connect to SQL Server Client 11.0
There are several ways you can use Python to connect to SQL Server and one of such ways is to use pyodbc and sqlalchemy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[crayon-68431df35da6e703888166 inline="true" ]import sqlalchemy import pyodbc try: import urllib params = urllib.quote_plus("DRIVER={SQL Server Native Client 11.0};SERVER=.\MSSQLSERVER_ENT;DATABASE=MagicDirect;Trusted_Connection=yes;") engine = sqlalchemy.create_engine('mssql+pyodbc:///?odbc_connect=%s"' % params) results.to_sql("clusterSegments", engine, if_exists = 'replace')# except (RuntimeError, TypeError, NameError): print('Error in Conneccting') print(RuntimeError, TypeError, NameError) finally: print("connected") |