How to fix Error 5141 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 5141 — Failed to Lock Credential Manager

Why This Error Happens

Error 5141 occurs when SQL Server 2025 is unable to acquire an internal lock on the Credential Manager subsystem, which governs access to database-scoped credentials, encryption keys, and external resource mappings. This typically happens due to a concurrency conflict where another session, DDL operation, or background task (such as a backup or key rotation process) is already holding the lock. It can also result from a corrupted master database metadata entry or insufficient permissions on the service account used to manage Credential Manager objects.

Step-by-Step Resolution Guide

Step 1: Identify Blocking Sessions and Processes

  • Run sp_who2 or query sys.dm_exec_requests to check for sessions blocking credential-related operations.
  • Look specifically for wait types such as CREDENTIAL_MANAGER_LOCK or similar internal resource waits in sys.dm_os_wait_stats.
  • Terminate any long-running or orphaned sessions using KILL <session_id> if they are confirmed safe to end.

Step 2: Verify Service Account Permissions

  • Confirm the SQL Server service account has appropriate rights on the master database and local machine key store.
  • Check that the account has CONTROL SERVER or at minimum ALTER ANY CREDENTIAL permission:
  GRANT ALTER ANY CREDENTIAL TO [DOMAIN\ServiceAccount];
  • Validate that Windows Credential Manager (on Windows Server 2025 / Windows 11) isn’t being restricted by Group Policy or antivirus software intercepting credential store access.

Step 3: Restart SQL Server Services Cleanly

  • Stop all dependent SQL Server services (SQL Server Agent, Reporting Services) before restarting the main engine.
  • Use PowerShell to restart cleanly:
  Restart-Service -Name 'MSSQLSERVER' -Force
  • This clears any stale in-memory locks tied to the Credential Manager subsystem.

Step 4: Rebuild or Repair Corrupted Credential Metadata

  • If the issue persists, script out all existing credentials using sys.credentials for backup purposes.
  • Drop and recreate the affected credential:
  DROP CREDENTIAL [CredentialName];
  CREATE CREDENTIAL [CredentialName] WITH IDENTITY = 'IdentityName', SECRET = 'StrongSecretValue';
  • This resolves cases where metadata corruption is preventing the lock from releasing properly.

Alternative or Verification Steps

  • After applying fixes, re-run the operation that originally triggered Error 5141 and confirm no entry appears in the SQL Server error log (Log_X.trc or Event Viewer under Applications and Services Logs > MSSQLSERVER).
  • If the error recurs intermittently, consider enabling Trace Flag 1222 temporarily to capture deadlock/lock contention details for deeper root-cause analysis.