Created
December 30, 2015 12:41
-
-
Save KentaYamada/16e020166aa38ecae2c3 to your computer and use it in GitHub Desktop.
Connect MSSQL(ODBC)
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
#-*- coding utf-8 -*- | |
import pyodbc | |
def test(): | |
connectString = "DRIVER={SQL SERVER}; SERVER=(local)\SQLEXPRESS;DATABASE=;TrustedConnction=yes;" | |
sql = "select sysdb.name from sysdatabases sysdb" | |
#connect server | |
with pyodbc.connect(connectString) as conn: | |
cursor = conn.cursor() | |
cursor.execute(sql) | |
for row in cursor.fetchall(): | |
#Output db name | |
print("Name:{0}".format(row)) | |
if __name__ =="__main__": | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment