繁体   English   中英

使用 Python 中的凭据连接到 SQL 服务器

[英]Connecting to SQL server using credentials in Python

我遇到了无法使用凭据连接到 SQL 服务器的问题。 使用受信任的连接时我可以连接 = 是。 我在这里做错了吗? 是否应该添加或考虑某些内容?

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
                  'Server=1070010-01;'
                  'Database=test_DB;'
                  'Uid =sa;'
                  'Pwd =SDTK-1111;'
                 )

我也试过用用户名和密码替换 Uid 和 Pwd。 我还尝试添加trusted_connection = no 在上述所有情况下,我都会收到此错误:

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};'
pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user ''. (18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0); [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user ''. (18456); [28000] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0)")

试试这个,字符串格式不正确

  conn = pyodbc.connect('Driver={SQL Server Native Client 11.0}; Server=1070010-01; uid=sa; pwd=SDTK-1111; Database = test_DB; Trusted_Connection=No;')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM