【问题标题】:Connecting to SQL server using credentials in Python在 Python 中使用凭据连接到 SQL Server
【发布时间】:2020-04-16 22:41:25
【问题描述】:

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

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

我也试过用 username 和 password 替换 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)")

【问题讨论】:

标签: python sql-server python-3.x


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 2019-03-21
    • 1970-01-01
    • 2010-10-07
    • 2022-01-06
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    相关资源
    最近更新 更多