我已经尝试使用Windows身份验证没有运气pypyodbc和pymssql。 任何想法?我可以登录时使用用户名和密码,但我不想这样做。我想使用Windows身份验证。如何使用Python上的Windows验证登录MSSQL?
我实际上只能得到pypyodbc的工作。我用pymssql得到了不同的连接错误。我搜索了不同的例子,他们不工作。我想我没有使用正确的格式用户名或东西。我必须将“DomainName \ myusername”放在那里,而不仅仅是我的用户名吗?我试过这个没有运气。
我该如何将其转换为Windows身份验证登录?
import pypyodbc
connection = pypyodbc.connect('Driver={SQL Server};'
'Server=IPaddresshere;'
'Database=PythonTest;'
'uid=myuser;pwd=mypass')
cursor = connection.cursor()
SQLCommand = ("SELECT FirstName, LastName, UID "
"FROM dbo.member "
"WHERE UID = ?")
Values = [2]
cursor.execute(SQLCommand,Values)
results = cursor.fetchone()
# note: UID column is an integer. You can't normally take an integer and place it in a string.
# so you must add str(results[2])
print("Employee " + results[0] + " " + results[1] + " ID is " + str(results[2]))
connection.close()