Cannot set a credential for principal 'sa'. (Microsoft SQL Server,错误: 15535)

 在SQL SERVER 2008上上禁用sa登录时,遇到下面错误:“Cannot set a credential for principal 'sa'. (Microsoft SQL Server,错误: 15535)”

clipboard

官方文档https://support.microsoft.com/zh-cn/kb/956177 分析了原因以及解决方案。

出现原因

如 果在登录属性-sa对话框的常规选项卡上未选中映射到凭据复选框,将出现此问题。如果未选中此复选框,则 SQL Server 2008年将尝试除去任何凭据映射到您的登录凭据。因为您的凭据不能设置为"sa"的登录,您将收到时单击确定关闭对话框"症状"一节中提到的异常错误消 息。

 

This problem occurs if the Map To Credential check box is not selected on the General tab of the Login Properties - sadialog box. If this check box is not selected, SQL Server 2008 will try to drop any credential that is mapped to your login credentials. Because your credentials cannot be set to the "sa" login, you receive the exception error message that is mentioned in the "Symptoms" section when you click OK to close the dialog box.

解决方案

要解决此问题,请确保您选择登录属性-sa对话框的常规选项卡上的映射到凭据复选框,您更改"sa"的登录属性,然后单击确定以关闭该对话框之前。

clipboard[1]

有关调用实时(JIT)调试而不是此对话框的详细信息, 请参见此消息的结尾。 ************** 异常文本 ************** System.Data.SqlClient.SqlException (0x80131904): 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联。 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) 在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) 在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 在 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) 在 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) 在 System.Data.SqlClient.SqlConnection.Open() 在 RemoteServiceClient.Form_MyComSettting..ctor() 在 RemoteServiceClient.Form_RTCClient.button_COMSETTING_Click(Object sender, EventArgs e) 在 System.Windows.Forms.Control.OnClick(EventArgs e) 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.Label.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ClientConnectionId:034ac75c-0fc7-4bd0-baf9-921e50542fa1 Error Number:18452,State:1,Class:14 ************** 已加载的程序集 ************** mscorlib 程序集版本:4.0.0.0 Win32 版本:4.8.9310.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll ---------------------------------------- RemoteServiceClient 程序集版本:1.0.0.0 Win32 版本:1.0.0.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/RemoteServiceClient.exe ---------------------------------------- System.Windows.Forms 程序集版本:4.0.0.0 Win32 版本:4.8.9251.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System 程序集版本:4.0.0.0 Win32 版本:4.8.9310.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Drawing 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Core 程序集版本:4.0.0.0 Win32 版本:4.8.9297.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll ---------------------------------------- System.Configuration 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Xml 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- Microsoft.GeneratedCode 程序集版本:1.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Runtime.Serialization 程序集版本:4.0.0.0 Win32 版本:4.8.9241.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll ---------------------------------------- Newtonsoft.Json 程序集版本:13.0.0.0 Win32 版本:13.0.3.27908 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Newtonsoft.Json.DLL ---------------------------------------- System.ServiceModel 程序集版本:4.0.0.0 Win32 版本:4.8.9241.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.ServiceModel/v4.0_4.0.0.0__b77a5c561934e089/System.ServiceModel.dll ---------------------------------------- System.Web.Extensions 程序集版本:4.0.0.0 Win32 版本:4.8.9282.0 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Extensions/v4.0_4.0.0.0__31bf3856ad364e35/System.Web.Extensions.dll ---------------------------------------- System.Data 程序集版本:4.0.0.0 Win32 版本:4.8.9214.0 built by: NET481REL1LAST_B 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll ---------------------------------------- System.Web 程序集版本:4.0.0.0 Win32 版本:4.8.9282.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll ---------------------------------------- Microsoft.SqlServer.Smo 程序集版本:17.100.0.0 Win32 版本:17.100.61.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.SqlServer.Smo.DLL ---------------------------------------- Microsoft.SqlServer.Management.Sdk.Sfc 程序集版本:17.100.0.0 Win32 版本:17.100.61.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.SqlServer.Management.Sdk.Sfc.DLL ---------------------------------------- Microsoft.SqlServer.ConnectionInfo 程序集版本:17.100.0.0 Win32 版本:17.100.61.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.SqlServer.ConnectionInfo.DLL ---------------------------------------- Microsoft.SqlServer.SqlEnum 程序集版本:17.100.0.0 Win32 版本:17.100.61.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.SqlServer.SqlEnum.DLL ---------------------------------------- Microsoft.Data.SqlClient 程序集版本:5.0.0.0 Win32 版本:5.16.24240.05 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.Data.SqlClient.DLL ---------------------------------------- System.Transactions 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll ---------------------------------------- Microsoft.SqlServer.SqlClrProvider 程序集版本:17.100.0.0 Win32 版本:17.100.61.0 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/Microsoft.SqlServer.SqlClrProvider.DLL ---------------------------------------- System.Runtime.InteropServices.RuntimeInformation 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.InteropServices.RuntimeInformation/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Runtime.InteropServices.RuntimeInformation.dll ---------------------------------------- System.Memory 程序集版本:4.0.1.1 Win32 版本:4.6.28619.01 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/System.Memory.DLL ---------------------------------------- System.Runtime.CompilerServices.Unsafe 程序集版本:6.0.0.0 Win32 版本:6.0.21.52210 基本代码:file:///C:/Users/%E6%9D%8E%E5%87%AF%E5%8D%8E/Desktop/%E7%BB%B4%E6%8A%A4%E5%AE%A2%E6%88%B7%E7%AB%AF2025.6.3/System.Runtime.CompilerServices.Unsafe.DLL ---------------------------------------- System.Data.resources 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Data.resources.dll ---------------------------------------- System.EnterpriseServices 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll ---------------------------------------- mscorlib.resources 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll ---------------------------------------- System.Windows.Forms.resources 程序集版本:4.0.0.0 Win32 版本:4.8.9037.0 built by: NET481REL1 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll ---------------------------------------- ************** JIT 调试 ************** 要启用实时(JIT)调试, 该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置 jitDebugging 值。 编译应用程序时还必须启用 调试。 例如: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> 启用 JIT 调试后,任何未经处理的异常 都将被发送到在此计算机上注册的 JIT 调试程序, 而不是由此对话框处理。客户端出现上述问题无法运行如何处理
06-25
<think>我们正在处理一个关于SQLServer登录失败和JIT调试的问题。用户遇到了“用户'sa'登录失败,该用户与可信SQLServer连接无关联”的错误,并希望了解如何处理这个异常以及如何启用JIT调试。首先,我们分析错误信息:1.“用户'sa'登录失败”:表明使用'sa'(系统管理员)账户尝试登录SQLServer时失败。2.“该用户与可信SQLServer连接无关联”:这通常与SQLServer的身份验证模式有关。SQLServer有两种身份验证模式:Windows身份验证和混合模式(Windows身份验证和SQLServer身份验证)。这个错误可能意味着:-SQLServer实例配置为仅使用Windows身份验证,而尝试使用SQLServer身份验证(即使用用户名和密码)登录。-或者,连接字符串中可能指定了“Trusted_Connection=True”(或等效设置),这表示使用当前Windows账户进行身份验证,但同时又提供了'sa'凭据,两者冲突。接下来,我们考虑如何解决:1.检查SQLServer的身份验证模式:-可以通过SQLServerManagementStudio(SSMS)连接到服务器(使用Windows身份验证)。-右键单击服务器实例,选择“属性”,然后选择“安全性”选项卡。-确保服务器身份验证设置为“SQLServer和Windows身份验证模式”。-修改后需要重启SQLServer服务。2.确保'sa'账户已启用:-在SSMS中,展开“安全性”->“登录名”,右键单击'sa',选择“属性”。-在“常规”选项卡中,检查是否设置了密码(如果使用SQLServer身份验证,必须设置密码)。-在“状态”选项卡中,确保“登录”设置为“启用”。3.检查连接字符串:-如果使用连接字符串连接数据库,确保它正确配置。例如:-使用SQLServer身份验证:`"DataSource=服务器名;InitialCatalog=数据库名;UserID=sa;Password=密码;"`-注意:不要包含`Trusted_Connection=True`(或`IntegratedSecurity=True`),因为这会强制使用Windows身份验证。4.检查SQLServer是否允许远程连接:-在SQLServer配置管理器中,确保TCP/IP协议已启用。关于JIT(Just-In-Time)调试:-JIT调试是指在程序运行过程中发生未处理的异常时,系统会启动一个调试器(如VisualStudio)来调试该异常。-启用JIT调试:1.对于.NET应用程序,可以在机器配置文件中启用,或者通过VisualStudio设置。2.在VisualStudio中:工具->选项->调试->实时调试,勾选“启用实时调试”。3.也可以通过注册表设置(需谨慎):-打开注册表编辑器(regedit)。-导航到:`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\AeDebug`-设置`Debugger`的值,例如:`"C:\Windows\system32\vsjitdebugger.exe"-p%ld-e%ld`-设置`Auto`为`1`(启用)或`0`(禁用)。-注意:启用JIT调试后,当应用程序崩溃时,系统会弹出调试器选择对话框,可以选择VisualStudio进行调试。但是,请注意,在服务器环境中启用JIT调试可能会带来安全风险,因为它允许在服务崩溃时启动调试器。因此,通常只在开发或诊断问题时启用。针对用户的问题,我们建议:1.首先解决SQLServer登录问题,确保身份验证模式正确,'sa'账户启用,并且连接字符串正确。2.如果需要在客户端应用程序中捕获并处理这个异常,可以使用try-catch块(具体语言取决于客户端使用的编程语言)。-例如,在C#中:```csharptry{//连接数据库的代码}catch(SqlExceptionex){//处理异常,例如记录日志或显示友好消息if(ex.Number==18452)//登录失败错误号{//处理登录失败}}```-错误号18452表示登录失败(使用SQLServer身份验证时登录失败)。3.如果需要在发生未处理异常时启用JIT调试以进行诊断,可以按照上述方法启用。注意:在用户的问题中,引用[1]是关于Metasploit捕获MSSQL凭据的,与当前问题无关;引用[2]是关于Qt网络模块的错误信号名称变更;引用[3]是关于SQL的INTERSECT运算符。这些引用可能不是用户直接需要的,但我们可以忽略它们,因为用户的问题集中在SQLServer登录和JIT调试上。最后,生成相关问题:1.如何配置SQLServer以允许'sa'登录?2.在连接字符串中,Windows身份验证和SQLServer身份验证有什么区别?3.如何在C#中捕获和处理SQLServer登录异常?4.启用JIT调试有哪些注意事项?5.如何禁用JIT调试?</think>### SQL Server 登录失败与 JIT 调试处理指南 #### 错误分析:`用户 'sa' 登录失败,该用户与可信 SQL Server 连接无关联` 该错误通常由以下原因导致: 1. **身份验证模式冲突** SQL Server 配置为仅接受 **Windows 身份验证**,但连接请求使用了 SQL Server 身份验证(如 sa 账户)。需检查: ```sql SELECT SERVERPROPERTY('IsIntegratedSecurityOnly') -- 返回1表示仅Windows验证 ``` 2. **连接字符串配置错误** 连接字符串中可能错误指定了 `Trusted_Connection=True`(强制 Windows 身份验证)与 SQL 账户混用: ```csharp // 错误示例(冲突配置) "Server=localhost; Database=test; User ID=sa; Password=xxx; Trusted_Connection=True;" ``` 3. **sa 账户未启用** 在 SQL Server Management Studio (SSMS) 中检查: ```sql ALTER LOGIN sa ENABLE; -- 启用账户 GRANT CONNECT SQL TO sa; -- 授予连接权限 ``` #### 解决方案步骤: 1. **修改身份验证模式** - 通过 SSMS:右键服务器 → 属性 → 安全性 → 勾选 **SQL Server 和 Windows 身份验证模式** - 重启 SQL Server 服务 2. **修正连接字符串** 移除 `Trusted_Connection` 或 `Integrated Security` 参数: ```csharp // 正确配置(SQL 身份验证) "Server=localhost; Database=test; User ID=sa; Password=xxx;" ``` 3. **检查 TCP/IP 协议** 在 SQL Server 配置管理器中启用 TCP/IP 协议,确保端口 1433 开放。 4. **防火墙设置** 允许入站规则:`%ProgramFiles%\Microsoft SQL Server\MSSQL\Binn\sqlservr.exe` #### JIT (Just-In-Time) 调试启用方法 当发生未处理异常时自动启动调试器: 1. **Windows 全局启用** ```reg Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug] "Debugger"="C:\Windows\system32\vsjitdebugger.exe -p %ld -e %ld" "Auto"="1" ``` 2. **.NET 应用程序配置** 在 `App.config` 中添加: ```xml <configuration> <system.windows.forms jitDebugging="true" /> </configuration> ``` 3. **Visual Studio 设置** 工具 → 选项 → 调试 → 实时调试 → 勾选 **启用实时调试** > **注意**:JIT 调试在生产环境中应谨慎使用,可能暴露敏感信息。调试完成后建议禁用[^2]。 #### 异常处理代码示例(C#) ```csharp try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); // 数据库操作 } } catch (SqlException ex) when (ex.Number == 18452) // 登录失败错误号 { Console.WriteLine($"身份验证错误: {ex.Message}"); // 记录日志或提示用户检查凭据 } catch (Exception ex) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); // 触发JIT调试 } throw; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值