简体   繁体   English

pyodbc - 无法使用可信连接登录

[英]pyodbc - Unable to login using trusted connection

I am able to login to SQL Server in SSMS using Windows authentication.我能够使用 Windows 身份验证在 SSMS 中登录到 SQL Server。

{Image removed due to exposure of real email address} {图片因真实邮箱地址曝光而删除}

But when I try the same using pyodbc it fails:但是当我使用pyodbc尝试相同时,它失败了:

import pyodbc

cnxn_str = (
    r'DRIVER=ODBC Driver 17 for SQL Server;'
    r'SERVER=.\SQLEXPRESS02;'
    r'Trusted_Connection=yes;'
    r'DATABASE=Scenario2025Max_Release 5.0_0523586A6813B825D031545D6E25A815;'
)

cnxn = pyodbc.connect(cnxn_str)

I get this error:我收到此错误:

Traceback (most recent call last):回溯(最近一次调用最后一次):

File "", line 30, in文件“”,第 30 行,在
pyodbc.InterfaceError: ('28000', '[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'MicrosoftAccount\\XXXXXXXX@outlook.com'. (18456) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot open database "Scenario2025Max_Release 5.0_0523586A6813B825D031545D6E25A815" requested by the login. The login failed. (4060); [28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'MicrosoftAccount\\XXXXXXXXAccount@domain.com'. (18456); [28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot open database "Scenario2025Max_Release 5.0_0523586A6813B825D031545D6E25A815" requested by the login. The login failed. (4060)') pyodbc.InterfaceError: ('28000', '[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]用户'MicrosoftAccount\\XXXXXXXX@outlook.com'登录失败。(18456) (SQLDriverConnect); [ 28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]无法打开数据库“Scenario2025Max_Release 5.0_0523586A6813B825D031545D6E25A815”登录请求。登录失败。(4060)Microsoft ODBC驱动程序[070] [218000]服务器][SQL Server]用户 'MicrosoftAccount\\XXXXXXXXAccount@domain.com' 登录失败。(18456); [28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]无法打开数据库“Scenario2025Max_Release 5.0_0523586A681053E825A68106E825A登录请求。登录失败。(4060)')

How is this possible?这怎么可能?

UPDATE - Added SQL Server logs for the error run -更新 - 为错误运行添加了 SQL Server 日志 - 在此处输入图片说明

I went through at least a hundred web pages over 2 full days on this, tried everything that was posted on StackOverflow threads, SQL/pyodbc/connectionsstrings blogs - restarting SQL Server, restarting my computer, modifying connection strings, changing SQL Server user permissions, but nothing worked.我花了整整两天的时间浏览了至少一百个网页,尝试了在 StackOverflow 线程、SQL/pyodbc/connectionsstrings 博客上发布的所有内容 - 重新启动 SQL Server,重新启动我的计算机,修改连接字符串,更改 SQL Server 用户权限,但没有任何效果。

Ultimately, I re-installed SQL Server entirely and I don't get the login failed error anymore, at least for now.最终,我完全重新安装了 SQL Server,并且我不再出现登录失败错误,至少现在是这样。

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

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