Connect Python to MS SQL Server using pyodbc

781 Views Asked by At

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
1

There are 1 best solutions below

3
On

Try...

...

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