![](/img/trans.png)
[英]Fix "login failed for user.." error in connecting Microsoft SQL server in Python
[英]Login failed for user '' when connecting to SQL Server using Python
我正在嘗試使用以下代碼使用 Python 連接到 SQL 服務器數據庫:
conn = pyodbc.connect(
r'Driver={SQL Server Native Client 11.0};'
r'Server=12345.dcd_ba.weatherton.com;'
r'Database=Dentrix;'
r'Trusted_Connection=no;'
r'Integrated security=false;'
r'username=fred;'
r'password=test;'
)
return conn
但我收到此錯誤:
pyodbc.InterfaceError: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]用戶''登錄失敗。(18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 11.0]無效的連接字符串屬性 (0);[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]用戶 '' 登錄失敗。(18456);[28000] [Microsoft][SQL Server Native客戶端 11.0]無效的連接字符串屬性 (0)")
根據Using Connection String Keywords with SQL Server Native Client看來您需要使用UID
而不是username
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.