Created
May 15, 2017 11:31
-
-
Save azhar22k/9105e4ab6f8f7d49776938dd83e99b16 to your computer and use it in GitHub Desktop.
Sample code to connect to MS SQL Server using python3
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 characters
#!/usr/bin/python3 | |
def sqlServerConnect(driverType,pip, pdbname, pusername="", ppwd=""): | |
from pyodbc import connect | |
try: | |
#trying to create a cnnection | |
connection = connect(driver=driverType, host=pip, database=pdbname, user=pusername,password=ppwd) | |
print("Connection successful : "+driverType+" "+pip+" "+" "+pdbname+" "+pusername) | |
return connection | |
except Exception as e: | |
#connection creation failed | |
print(e) | |
return None | |
sqlServerConnect('{ODBC Driver 13 for SQL Server}','server_name/ip','databse_name','username','password') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment