简体   繁体   English

使用 Python 连接到 SQL 服务器时,用户 '' 登录失败

[英]Login failed for user '' when connecting to SQL Server using Python

I am trying to connect to a SQL Server database with Python using this code:我正在尝试使用以下代码使用 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

But I am getting this error:但我收到此错误:

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)") 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)")

According to Using Connection String Keywords with SQL Server Native Client it looks like you need to use UID instead of username根据Using Connection String Keywords with SQL Server Native Client看来您需要使用UID而不是username

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

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