我在笔记本电脑上安装并配置了 IIS7,并使用了 python cgi 接口。我可以从 Eclipse 中运行 python 脚本并从数据库中获取我正在寻找的结果。但是当我从网页运行脚本时,我得到一个身份验证错误。似乎连接字符串没有将凭据传递给 SQL 服务器。有什么想法吗?
import pyodbc
import cgi
import cgitb; cgitb.enable()
cnxn = pyodbc.connect(driver='{SQL Server}',
server='SERVER\INSTANCE',
Trusted_Connection='yes',
database='Test_Chad',
uid='SERVER\username',
pwd='password')
def getRow():
cursor = cnxn.cursor()
cursor.execute("select user_id, user_name from users")
row = cursor.fetchone()
print 'name:', row.user_id
print 'name:', row.user_name
getRow()
例外:
<class 'pyodbc.Error'>: ('28000', "[28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.
(18456) (SQLDriverConnect); [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'. (18456)")
args = ('28000', r"[28000] [Microsoft][ODBC SQL Server Driver][SQL ... for user 'NT AUTHORITY\ANONYMOUS LOGON'. (18456)")
message = ''