0

I am connecting to an MS SQL server with pymssql. I can connect by tsql -H ip -p 1433 -U xx - p xx and by jupyter notebook. The connection does not return any errors.

However, I tried many queries with pymssql but none of them returned results.

For example, cursor.execute('SELECT * FROM INFORMATION_SCHEMA.TABLES ')

What should I check now?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Jill Clover
  • 2,168
  • 7
  • 31
  • 51

1 Answers1

0

As mentioned in the "Iterating through results" section of the pymssql examples, you can simply iterate through the rows of the result set like this:

crsr = conn.cursor()
crsr.execute("SELECT * FROM INFORMATION_SCHEMA.TABLES")
for row in crsr:
    print(row)

Or, to use a more standard DB-API approach:

crsr = conn.cursor()
crsr.execute("SELECT * FROM INFORMATION_SCHEMA.TABLES")
for row in crsr.fetchall():
    print(row)
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418