On this page
Why it happens
Error 4060 happens at a very specific point: the login itself passed authentication, so the server knows who you are, but the next step (opening the database named in the connection) failed. The message names the database in quotes, for example Cannot open database "AppDb", which is your fastest clue about what the connection actually asked for.
There are three common reasons the open fails. The database name is wrong or the database does not exist on this server, so there is nothing to open. The database exists but is not ONLINE (it may be OFFLINE, RESTORING, or SUSPECT), so it cannot accept connections. Or the database exists and is online, but the login has no matching database user or CONNECT permission inside it, so the server refuses to let that login in.
This is severity 11, an informational connection error, not a server fault. Note the difference from error 18456: 18456 means the login never authenticated at all (bad password or unknown login), while 4060 means the login was accepted and only the database open step failed.
Examples
Connecting to a database that is OFFLINE or missing
-- The login AppUser is valid, but the target database
-- named in the connection string cannot be opened.
-- Example: the connection asks for AppDb while it is OFFLINE.
ALTER DATABASE AppDb SET OFFLINE;
-- A new connection that requests AppDb now fails to open it.
Cannot open database "AppDb" requested by the login. The login failed. Login failed for user 'AppUser'.
Login has no user inside the requested database
-- A server login exists, but no matching user was ever
-- created inside AppDb, so the login cannot open it.
CREATE LOGIN AppUser WITH PASSWORD = 'StrongPassw0rd!';
-- Connecting with Initial Catalog = AppDb fails, because
-- AppUser has no user or CONNECT permission in that database.
Cannot open database "AppDb" requested by the login. The login failed. Login failed for user 'AppUser'.
How to fix it
Verify the database name and that it is ONLINE
First confirm the database exists on this server and check its state. Query sys.databases and read state_desc. If it is not ONLINE, bring it online.
-- Confirm the database exists and check its state.
SELECT name, state_desc
FROM sys.databases
WHERE name = 'AppDb';
-- If state_desc is OFFLINE, bring it back online.
ALTER DATABASE AppDb SET ONLINE;
Create a user for the login and grant a role
If the database is online but the login has no user inside it, create one from the login and add it to a role so it has access. Run this while connected as an administrator to the target database.
USE AppDb;
GO
-- Map the server login to a database user.
CREATE USER [AppUser] FROM LOGIN [AppUser];
-- Grant read access (add db_datawriter too if writes are needed).
ALTER ROLE db_datareader ADD MEMBER [AppUser];
Correct the database name in the connection string
If the requested database simply does not exist, the connection is pointing at the wrong name. Fix the Initial Catalog (or Database) value so it matches an existing, online database.
-- Wrong: Initial Catalog points at a database that does not exist.
-- Server=myserver;Initial Catalog=AppDb;User ID=AppUser;Password=...;
-- Right: use the exact, existing database name.
-- Server=myserver;Initial Catalog=ApplicationDb;User ID=AppUser;Password=...;
How to prevent it
Keep connection strings correct and version controlled so every environment points at a real, online database. A single wrong Initial Catalog value is the most common cause of 4060, and it is easy to catch before deployment.
Grant database access as part of deployment. When you provision a login, also create its user in the target database and add the needed roles, so the login can actually open the database it will connect to. Review who can enter each database in the SQL Server security guide.
Common questions
How do I fix SQL Server error 4060?
Make sure the requested database is real and reachable. Confirm the name in your connection string matches an existing database, check that it is ONLINE using sys.databases state_desc (and run ALTER DATABASE ... SET ONLINE if it is not), and create a user for the login inside that database with CREATE USER and a role like db_datareader so the login is allowed to open it.
What is the difference between error 4060 and error 18456?
Error 18456 means the login itself failed to authenticate, usually a wrong password or an unknown login, so the server never accepted you. Error 4060 happens after authentication succeeds: the login is valid, but it cannot open the specific database it requested, because that database is missing, offline, or the login has no user or permission inside it.
Why does error 4060 say the login failed when the password is correct?
The password is fine and the login authenticated. The message says the login failed only because opening the requested database failed, which is the last step of establishing the connection. Look at the database name in quotes, confirm it exists and is online, and make sure the login has a user in it.