我是 python 新手。我正在尝试查询 MSSQL 数据库。
import pymssql
conn = pymssql.connect(host='hostname', user='username', password='password', database='dbname')
cursor = conn.cursor()
sql = "select count(*) from T_Email with (nolock) where Transmit is null"
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
print (row)
成功运行的查询是 Microsoft SQL Server Management Studio,但我的 python 脚本始终没有返回任何内容。
我确认我有网络连接。我验证了用户名、密码和数据库名称。如果我更改密码,那么脚本会出错。
我已经尝试过 results = cursor.fetchone(),但这并没有帮助。
有什么建议么?