// SQL Server error reference

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
Error message
Cannot open user default database. Login failed.

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

  1. Connect anyway by naming an available database in the connection, for example master. In SSMS that's Options, Connection Properties, Connect to database.

  2. Point the login's default database at one that exists.

    ALTER LOGIN app_user WITH DEFAULT_DATABASE = master;
  3. 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

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.

// fewer errors, faster fixes

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.