SQL Server Error 4064: Cannot Open User Default Database

Error 4064 means the connection cannot open the database SQL Server is trying to use as that login's default/start database in this connection context. Do not permanently switch the login to master as your first move. First prove whether the same identity can connect through another permitted database, identify the actual instance/replica that handled the attempt, then determine why the intended database cannot open there. Repair that cause before deciding whether DEFAULT_DATABASE is genuinely wrong.

SQL Server · MSSQLSERVER_4064 · LoginDefault database · Availability · AccessLast reviewed Sep 27, 2026
🎯 You’re likely in the right place if:
SSMS or an application says Cannot open user default database. Login failed.The client reports Microsoft SQL Server, Error: 4064.The credentials may be valid, but SQL Server cannot open the login’s default database.
Choose your path after you escape the broken default database
You cannot get into SSMS →Specify an available database such as master for this connection only, if your login is allowed to use it.Database was renamed or dropped →Confirm the intended replacement before changing the login’s DEFAULT_DATABASE.Database is OFFLINE / RESTORING / RECOVERY_PENDING / SUSPECT →Repair the database state; changing the login can hide the real outage.Database is ONLINE but access is restricted →Check SINGLE_USER, RESTRICTED_USER and who is consuming the allowed connection.Database is ONLINE but this login still cannot open it →Verify the intended database user/access instead of granting broad server rights.The default database is genuinely obsolete →Change DEFAULT_DATABASE to the intended durable database, not automatically to master.
Difficulty: ModerateSafe if scoped
🛟 Quick Fix — escape through an available database first

In SSMS, open Options → Connection Properties and specify a database that is currently available and that this login is actually permitted to open. Microsoft documents this as a way to bypass a broken default database for diagnosis. master is a common administrative escape target, but do not assume every login is allowed to use it; another approved accessible database can serve the same diagnostic purpose. The override is an escape route, not automatically the correct permanent default.

Server: your-server\instance Database for this connection: master

Verify: the same identity can connect to the same endpoint/instance path when an approved accessible database is explicitly selected. If it cannot, stop treating this as only a 4064/default-database problem and inspect the actual login error—especially Error 18456 and its matching server-side Reason/State.

Did specifying an available database let you connect?
ADSENSE · reserved slot after the first useful step

Diagnose the database before changing the login

Once connected through an available database, inspect the login’s current default and the state/access mode of the intended database. SQL Server exposes database state through sys.databases; Microsoft documents states including ONLINE, RESTORING, RECOVERING, RECOVERY_PENDING, SUSPECT, EMERGENCY and OFFLINE, plus user-access modes MULTI_USER, SINGLE_USER and RESTRICTED_USER.

SELECT name, state_desc, user_access_desc FROM sys.databases ORDER BY name;

Also confirm the default database assigned to the login using an authorized administrative view or login properties, and confirm the actual server/replica that received the connection. With aliases, listeners, clusters or availability groups, a database can be usable on one node yet unavailable or non-readable in the role reached by another path. The key question is not “How do I make 4064 disappear?” but “Why can this login not open its intended start database on the server context it actually reached?”

Verify: You know the intended database name, whether it exists, its current state_desc, its user_access_desc, and whether the login should still use it as the default.

Fix #2 — database renamed, dropped, or the default points to the wrong name

A rename is a classic 4064 trigger. Microsoft specifically warns that if a renamed database was a login’s default, the login can encounter Error 4064 until its default is updated to the new database name.

If the old database was intentionally renamed, assign the login to the intended renamed database. If it was dropped because an application was retired, choose the correct durable database for that login rather than mechanically assigning master.

USE [master]; GO ALTER LOGIN [your_login] WITH DEFAULT_DATABASE = [intended_database]; GO

Permission boundary: run this as an authorized administrator with permission to alter that login. Do not grant the affected application login sysadmin or securityadmin merely so it can change its own routing. If you do not administer logins on this instance, capture the intended database and hand the change to the DBA.

Verify: Start a new connection without overriding the database. It should land in the intended database and Error 4064 should not return.

Fix #3 — OFFLINE, RESTORING, RECOVERY_PENDING, SUSPECT, or another unavailable state

If the intended default database still exists but is not ONLINE, the database state is the problem to solve. Microsoft defines OFFLINE as unavailable by explicit action; RESTORING/RECOVERING as recovery states; RECOVERY_PENDING as a resource-related recovery failure requiring action; and SUSPECT as a database that could not recover successfully.

Do not flatten these states into one “bring database online” command. A deliberately OFFLINE database, an active restore, RECOVERY_PENDING and SUSPECT have different causes and recovery procedures. Determine why the state exists before issuing ALTER DATABASE, repair, restore, attach, or file operations. RECOVERY_PENDING or SUSPECT is a recovery/incident branch, not a 4064 shortcut: preserve the evidence, check the SQL Server error log and storage/resource condition, and follow the approved restore/recovery procedure. This guide intentionally does not prescribe EMERGENCY, DBCC CHECKDB ... REPAIR_ALLOW_DATA_LOSS, detach/attach, or file deletion as a generic 4064 fix.

If the outage is temporary and the database is still supposed to be this login’s default, repair availability and leave the default assignment intact. Changing the login to master can make the symptom disappear while the actual database remains broken.

Verify: The intended database reaches the expected usable state and the login can start a fresh connection to it without a database override.

Fix #4 — ONLINE but SINGLE_USER or RESTRICTED_USER

An ONLINE database can still reject ordinary users because access mode is restricted. SINGLE_USER permits only one qualifying connection at a time; RESTRICTED_USER limits access to privileged database/server roles. Inspect user_access_desc before blaming the login password.

If SINGLE_USER was set for maintenance, identify whether another session is consuming the one connection and whether maintenance is still active. A monitoring agent, Object Explorer, application pool, or other background client can consume that single connection before your intended session. Do not repeatedly race those clients, kill sessions blindly, or force MULTI_USER while a restore, repair, migration, or controlled maintenance operation is still in progress. Coordinate with the DBA/maintenance owner and change access mode only when the maintenance plan says it is safe.

Verify: After the approved maintenance/access change, user_access_desc reflects the intended mode and the real login can open the database.

Fix #5 — database is ONLINE, but this login still cannot open it

If the database is ONLINE, check whether it is usable from the exact server/replica and connection intent that received the login, then whether the identity is intended to have access. ONLINE alone does not prove the database is readable for this path. Inspect the database user/principal, login-to-user SID mapping where applicable, containment model, CONNECT permission/explicit DENY, and replica/readability state before changing security principals. Do not solve an access problem by granting server-wide sysadmin.

Compare a known-good identity/path with the failing one and consider whether restore/migration/failover changed security mappings or availability context. An orphaned/mismatched user is one possible branch, not a universal explanation. Keep this separate from password troubleshooting: Error 4064 is about opening the start/default database, while Error 18456 provides broader login/authentication evidence.

Verify: the least-privileged intended identity can explicitly connect to the intended database through the same listener/instance/replica path and perform only the operations it is supposed to perform. Then test a new connection without the temporary database override.

Fix #6 — change DEFAULT_DATABASE only when the assignment itself is wrong

ALTER LOGIN ... WITH DEFAULT_DATABASE = ... is the correct durable fix when the login’s assigned default is genuinely obsolete or incorrect—for example after an intentional database rename. Microsoft documents DEFAULT_DATABASE as a login property.

Do not confuse escape with configuration. Connecting temporarily through master proves you can bypass the broken default. It does not prove that master should become the login’s permanent default.

Choose a durable default that matches how the login is actually used. Do not confuse the login default with an explicit application target: a connection string Initial Catalog=AppDb or Database=AppDb asks for that database explicitly and takes precedence over the login's default routing. If that explicit database is misspelled, offline, unavailable, or inaccessible, repair the explicit target or its availability/access. Changing DEFAULT_DATABASE will not repair a bad Initial Catalog.

Verify: Open a completely new connection with no temporary database override and confirm it lands where intended.

Platform boundary — SQL Server / Managed Instance vs Azure SQL Database

This article's Error 4064 and ALTER LOGIN ... DEFAULT_DATABASE workflow is primarily a SQL Server instance workflow. Azure SQL Database is database-scoped and does not support the SQL Server DEFAULT_DATABASE login option. Do not use that statement there; connect to the intended Azure SQL database explicitly and troubleshoot its user/login model with Azure SQL-specific guidance. Azure SQL Managed Instance is much closer to SQL Server's instance/login model, but still confirm the product and current syntax before making security changes.

What not to do

Do not permanently set every affected login to master just because it lets you connect.Do not reset the password unless authentication evidence actually points to a credential problem.Do not grant sysadmin to bypass a database-access problem.Do not force an OFFLINE, RESTORING, RECOVERY_PENDING or SUSPECT database into a new state without understanding why it is there.Do not kick a database out of SINGLE_USER/RESTRICTED_USER while approved maintenance is still running.Do not run ALTER LOGIN ... DEFAULT_DATABASE against Azure SQL Database; target the intended database explicitly and use Azure SQL-specific principal guidance.Do not use EMERGENCY mode, REPAIR_ALLOW_DATA_LOSS, detach/attach, or file deletion as generic responses to a 4064 symptom.Do not assume master is accessible to every affected login; use an approved database the identity can actually open for the diagnostic escape test.Do not assume ONLINE means usable on every availability-group replica or connection-intent path.Do not recreate/remap a database user until you have proved the login/user SID, containment and permission branch is actually wrong.Do not keep diagnosing 4064 once the intended database opens and the connection advances to a different authentication, permission or application error.

Still seeing Error 4064?

Separate the login's default from an explicitly requested database. If SSMS works when you choose an available database but the application still fails, inspect the application's effective connection string and configuration source. Initial Catalog / Database may explicitly request a missing, misspelled, offline, or inaccessible database. In that case the explicit target is the branch to repair; changing the login default is unrelated to the application's requested database.

Before escalating, capture:exact client error and error numberclient endpoint plus actual server/instance/replica that received the connection, and login identitycurrent login default databasedatabase name, state_desc, user_access_desc, and availability/replica readability context when applicablewhether explicit connection to master/another database succeedswhether the database was renamed, restored, detached, dropped, failed over, or placed in maintenancefor ONLINE-but-inaccessible cases: database principal/SID mapping, containment, CONNECT/DENY evidence and the exact replica/patheffective application database/Initial Catalog without secretsmatching SQL Server ERRORLOG reason/state if 18456 also appears

Official references

Still stuck? Ask the community

Share the redacted Error 4064 message, SQL Server version, login type, intended default database, state_desc, user_access_desc, and whether explicitly connecting to another database succeeds.

Keep it safe: never post passwords, secret-bearing connection strings, tokens, private keys, or confidential credentials.
Powered by GitHub DiscussionsSign in with GitHub to comment. Reading comments does not require sign-in.

Loading community discussion…