Troubleshooting Guide: SQL Server Error 4060 – “Cannot Open Database Requested by the Login”
Why This Error Happens
Error 4060 typically occurs because the login attempting to connect does not have an associated user account or permissions within the target database, or the default database specified for that login no longer exists or is inaccessible. This can also happen if the database is still in a RESTORING, OFFLINE, or SINGLE_USER state, or if the database name was misspelled in the connection string. In some cases, orphaned SIDs (Security Identifiers) between the login and the database user mapping can trigger this failure even when the user technically “exists.”
Step-by-Step Resolution Guide
Step 1: Verify the Database Status and Existence
- Open SQL Server Management Studio (SSMS) and connect using an administrative account (e.g.,
sa). - Run the following query to check the database state:
SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabaseName';
- Ensure the
state_descreturnsONLINE. If it showsRESTORINGorOFFLINE, you will need to restore the backup chain or bring the database back online manually.
Step 2: Check Login Permissions and Database Mapping
- Navigate to Security > Logins in SSMS, right-click the specific login causing the error, and select Properties.
- Go to the User Mapping tab and confirm the checkbox next to the target database is checked.
- If the mapping is missing, add it manually or run:
USE YourDatabaseName;
CREATE USER [YourLoginName] FOR LOGIN [YourLoginName];
- If the user already exists but is “orphaned,” repair the SID link using
ALTER USER [YourLoginName] WITH LOGIN = [YourLoginName];.
Step 3: Correct Firewall and Default Database Settings
- On Windows Server 2025, verify that the Windows Defender Firewall isn’t blocking the specific database instance port (though this usually throws a different error, misconfigured VLANs can sometimes cause intermittent connection drops that mimic 4060).
- Check the login’s “Default Database” setting in Login Properties > General. If it points to a decommissioned database, change it back to
masterto allow the login to connect first, then troubleshoot the specific DB access. - Restart the SQL Server (MSSQLSERVER) service via
services.mscif configuration changes were made at the instance level.
Step 4: Review SQL Server Error Logs
- Navigate to the default log path:
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG(path may vary based on the 2025 instance naming convention). - Look for specific sub-errors occurring alongside the 4060, such as “Login failed for user” combined with State codes (e.g., State 38 indicates the database does not exist, while State 5 indicates insufficient permissions).
Alternative or Verification Steps
- Verify the Fix: Attempt to log in via SSMS using the specific SQL login (not Windows Auth) and explicitly select the problematic database from the “Connect to Database” dropdown in the Options tab.
- Alternative Fix: If the user mapping continues to fail, drop the user from the database (
DROP USER [YourLoginName]) and recreate it, then manually re-assign the necessary roles (e.g.,db_datareader,db_datawriter) to rule out corrupted permission schemas.