简体   繁体   English

使用pyodbc将Python连接到MS SQL Server

[英]Connect Python to MS SQL Server using pyodbc

I am having a problem connecting pyodbc to my SQL Server. 我在将pyodbc连接到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']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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