使用Python连接到sql时出错

时间:2017-06-01 23:31:49

标签: python sql python-db-api

我正在使用Python库pymssql连接到数据库。我以前从未使用它,因此错误可能看起来微不足道。

from os import getenv
import pymssql

server = getenv("192.xxx.xxx.xx") 
user = getenv("john.constantine")
password = getenv("xxxxxxx")

conn = pymssql.connect(server, user, password, "tempdb")
cursor = conn.cursor()

cursor.execute('SELECT * from table')
rows = cursor.fetchall()
for row in rows:
    print row

conn.close()

我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\Documents\Demo_DB.py", line 8, in <module>
    conn = pymssql.connect(server, user, password, "tempdb")
  File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734)
  File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821)
  File "_mssql.pyx", line 552, in _mssql.MSSQLConnection.__init__ (_mssql.c:5891)
TypeError: argument of type 'NoneType' is not iterable
[Finished in 0.2s with exit code 1]

我使用这些凭据连接到数据库。 enter image description here

0 个答案:

没有答案