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

Troubleshooting Guide: SQL Server Error 4061

Why This Error Happens

Error 4061 occurs when the login attempting to connect does not have an associated database it can access, either because the requested database is offline, has been dropped, or is still recovering. This also commonly happens when the login’s configured “default database” no longer exists or the login lacks the CONNECT permission on that database. As a result, SQL Server 2025 falls back to using the master database as a safety measure, which often fails silently for applications expecting a specific schema.

Step-by-Step Resolution Guide

Step 1: Verify the Database State

  • Open SQL Server Management Studio (SSMS) and connect using an admin account (e.g., sa).
  • Run the query: SELECT name, state_desc FROM sys.databases;
  • Check if the target database status reads ONLINE. If it reads RECOVERY_PENDING or SUSPECT, the database files may be corrupted or the drive path is missing.

Step 2: Check and Reset the Login’s Default Database

  • Expand Security > Logins in SSMS, right-click the specific login, and select Properties.
  • Look at the Default database dropdown field; if it points to a database that was deleted, change it back to master temporarily.
  • Alternatively, run this T-SQL command to fix it via query:
  • ALTER LOGIN [YourLoginName] WITH DEFAULT_DATABASE = [master];

Step 3: Validate User Permissions and Mapping

  • Navigate to User Mapping under the Login Properties window.
  • Ensure the checkbox next to the target database is checked, granting the login access.
  • Verify the user has the db_datareader or appropriate role assigned; a mismatch between the Login (Server level) and the User (Database level) often triggers this error even if the database is online.

Step 4: Restart SQL Server Services

  • Open the Services app (services.msc) on Windows Server 2025 or Windows 11.
  • Locate SQL Server (MSSQLSERVER) or the specific named instance.
  • Right-click and select Restart to clear any cached connection states or locks that might be blocking the database file.

Alternative or Verification Steps

  • Verification: Attempt to reconnect using SSMS or your application; if successful, run SELECT DB_NAME(); to confirm you are no longer defaulting to the master database.
  • Alternative: If the database file (.mdf) is missing from the disk, restore the database from the latest .bak file using the Restore Database wizard in SSMS, ensuring the file paths match the original server configuration.