SQL Server error 4064: Cannot open user default database
The connection didn't name a database, and the login's default database is missing, offline or not accessible, so the login fails.
- Error number
4064- Severity
- 11
- Category
- Connection and login
What it means
Every login has a default database that SQL Server opens when a connection doesn't ask for a specific one. If that database was dropped, is offline, or the login has no user in it, the connection can't start and you get 4064.
Common causes
- The login's default database was dropped, renamed or detached.
- The default database is offline, restoring or in single-user mode.
- The login's database user was removed from its default database.
How to fix it
-
Connect anyway by naming an available database in the connection, for example
master. In SSMS that's Options, Connection Properties, Connect to database. -
Point the login's default database at one that exists.
ALTER LOGIN app_user WITH DEFAULT_DATABASE = master;
-
Check which default database each login has.
SELECT name, default_database_name FROM sys.server_principals WHERE type IN ('S', 'U', 'G');
Related errors
More connection and login errors
53Network-related or instance-specific18452Login is from an untrusted domain18470Login failed, account disabled18486Login failed, account locked out18487Login failed, password expired18488Login failed, password must be changed18461Login failed, single user mode
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.