Skip to main content

Error: 'Cannot open user default database. Login failed'

In this article, we address the 'Cannot open user default database. Login failed' error in the Admin Tool.

Y
Written by Yusef Abulaynain
Updated over 5 months ago

For hosted customers please raise a new case online and reference the title of this article. Please provide the name or URL of the Mosaic instance(s) and users login this relates too.
​
This issue occurs if the default database assigned to the SQL Login is offline or no longer exists.

How to manually fix a single login

  1. Open SQL Server Management Studio.

  2. Connect to the Database server.

  3. In Object Explorer in the left hand pane expand Security then Logins.

  4. Right click the login that has the issue.

  5. Select Properties.

  6. Select the drop down list next to Default Database in the General page and change to master.

  7. Click OK.

How to identify and fix logins en masse

  1. Check the login which has the issue using steps 1 - 5 above to confirm that the default database is offline or no longer exists.

  2. Run the following SQL replacing database_from_step_1 with the name of the default database from step 1.

    select 'alter login '+name+' with default_database=master' FROM sys.server_principals WHERE default_database_name='database_from_step_1' order by name

  3. Copy and paste the results from step 2 into a new Query and Execute the query, see example results below.

    alter login userlogin1 with default_database=master
    alter login userlogin2 with default_database=master
    alter login userlogin3 with default_database=master
Did this answer your question?