简体   繁体   中英

Connect Python to MS SQL Server using pyodbc

I am having a problem connecting pyodbc to my SQL Server. When I run it, there is no output at all and there is not error message or anything to tell me what is wrong? Even after I hit enter a few times nothing?

 import pyodbc
 cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=marketing-sql01.onlive.corp;DATABASE=grok;UID=austin.trombley;PWD=XXXX')
 cursor = cnxn.cursor()
 cursor.execute("select * from user")
 rows = cursor.fetchall()
 for row in rows:
      print row.user_id, row.user_name

Try...

...

for row in rows:
    print row['user_id'], row['user_name']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM