Sql server 4064 ошибка

Describes that you may receive an error message when you connect to an instance of SQL Server without specifying a login database.

Microsoft SQL Server 2005 Standard Edition Microsoft SQL Server 2005 Enterprise Edition Microsoft SQL Server 2005 Developer Edition Microsoft SQL Server 2005 Workgroup Edition Microsoft SQL Server 2005 Express Edition SQL Server 2008 Developer SQL Server 2008 Enterprise SQL Server 2008 Express SQL Server 2008 Express with Advanced Services SQL Server 2008 R2 Datacenter SQL Server 2008 R2 Developer SQL Server 2008 R2 Enterprise SQL Server 2008 R2 Express SQL Server 2008 R2 Express with Advanced Services SQL Server 2008 R2 Standard SQL Server 2008 R2 Standard Edition for Small Business SQL Server 2008 R2 Web SQL Server 2008 R2 Workgroup SQL Server 2008 Standard Edition for Small Business SQL Server 2008 Web SQL Server 2008 Workgroup SQL Server 2012 Developer SQL Server 2012 Enterprise SQL Server 2012 Express SQL Server 2012 Standard SQL Server 2012 Web SQL Server 2012 Enterprise Core SQL Server 2014 Developer SQL Server 2014 Developer SQL Server 2014 Enterprise SQL Server 2014 Enterprise SQL Server 2014 Express SQL Server 2014 Express SQL Server 2014 Standard SQL Server 2014 Standard SQL Server 2014 Web SQL Server 2014 Web SQL Server 2016 Standard SQL Server 2016 Enterprise Core SQL Server 2016 Developer SQL Server 2016 Enterprise SQL Server 2017 on Windows (all editions) More…Less

Symptoms

Each user has a default database. When you connect to computer that’s running Microsoft SQL Server, and you do not specify a login database, the default database is used. However, if the default database is unavailable at the time of the connection, you may not be able to connect. Instead, you receive error message 4062 or error message 4064, which resembles the following:

Cannot open user default database

Cause

The user default database is unavailable at the time of connection. It’s possible that the database:

  • Is in suspect mode.

  • No longer exists.

  • Is in single user mode and the only available connection is already being used by someone or something else.

  • Has been detached.

  • Has been set to the RESTRICTED_USER state.

  • Is offline.

  • Is set to emergency status.

  • Does not have the login account mapped to a user, or the user has been denied access.

  • Is part of a database mirror.

Additionally, the login account may be a member of multiple groups, and the default database for one of those groups is unavailable at the time of connection.

Workaround

To work around this behavior, specify a valid, available database in the connection string. To prevent the error when the user’s default database is unavailable, log on as a user who can modify logins. Then, change the user’s default database to a database that’s currently available for a connection.

SQL Server 2005 and later versions

You can use the sqlcmd utility to change the default database in SQL Server 2005. To do this, follow these steps:

  1. Click Start, click Run, type cmd, and then press ENTER.

  2. Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:

    • If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press ENTER:

      sqlcmd E -S InstanceName d master

    • If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press ENTER:

      sqlcmd -S InstanceName -d master -U SQLLogin -P Password

    Note InstanceName is a placeholder for the name of the SQL Server 2005 instance to which you are connecting. SQLLogin is a placeholder for the SQL Server login whose default database has been dropped. Password is a placeholder for the SQL Server login password.

  3. At the sqlcmd prompt, type the following, and then press ENTER:

    ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBNameNote AvailDBName is a placeholder for the name of the existing database that can be accessed by the SQL Server login in the instance.

  4. At the sqlcmd prompt, type GO, and then press ENTER.

SQL Server 2000 and SQL Server 7.0

You can use the osql utility to change the default database in SQL Server 2000 and in SQL Server 7.0. To do this, follow these steps:

  1. At a command prompt, type the following and then press ENTER:

    C:>osql -E -d master

  2. At the osql prompt, type the following and then press ENTER:

    1>sp_defaultdb ‘user’s_login’, ‘master’

  3. At the second prompt, type the following and then press ENTER:

    2>go

Status

This behavior is by design.

More Information

To reproduce this behavior, try to connect with OSQL, and use the -d option with an existing database that’s in a normal online state. The connection succeeds without any error message.

Conversely, you receive responses that resemble the following from various SQL Server client utilities when the database is unavailable:

  • SQL Server Management Studio (SQL Server 2005)

    Cannot connect to ServerName
    ADDITIONAL INFORMATION:
    Cannot open user default database. Login failed. Login failed for user ‘UserName‘. (Microsoft SQL Server, Error: 4064)

  • Using Sqlcmd utility in SQL Server 2005

    Msg 4064, Level 11, State 1, Server ServerName, Line 1
    Cannot open user default database. Login failed.

    Msg 18456, Level 14, State 1, Server ServerName, Line 1 Login failed for user ‘UserName‘.

  • SQL Server 2000 Query Analyzer (QA)

    Unable to connect to server TESTSERVER:
    Server: Msg 4064, Level 16, State 1
    [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open user default database. Login failed.

  • SQL Server 2000 Server Enterprise Manager (SEM)

    A connection could not be established to TESTSERVER — Cannot open user default database ‘dbid’. Using master database instead.

    Please verify SQL Server is running and check your SQL Server registration properties (by right-clicking on the TESTSERVER node) and try again.

  • A command prompt using SQL Server 2000 OSQL

    You receive the following error message when you use the C:>osql -E command:

    Cannot open user default database. Login failed.

  • SQL Server 7.0 Query Analyzer (QA)

    Unable to connect to server \TESTSERVER:
    Server: Msg 4062, Level 16, State 1
    [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open user default database ‘<ID>’. Using master database instead.

  • A command prompt using SQL Server 7.0 OSQL

    You receive the following error message when you use the C:>osql -E command:

    Cannot open user default database ‘dbid’.
    Using master database instead.

The following table provides more information about the products or tools that automatically check for this condition on your instance of SQL Server and on the versions of the SQL Server product against which the rule is evaluated.

Rule software

Rule title

Rule description

Product versions against which the rule is evaluated

System Center Advisor

SQL Server server-level principals configured with non-existent default database

System Center Advisor checks if any logins present in the SQL Server instance are configured with a default database that does not exist anymore. Review the details that are provided in the Information Collected section of the advisor alert, and follow the steps discussed in this article to resolve the situation.

SQL Server 2008

SQL Server 2008 R2

SQL Server 2012

SQL Server 2017 on Windows

Need more help?

SQL server error 4064 triggers while connecting to Microsoft SQL Server. This generally happens when the default database is not available to complete the connection requests.

As a part of our Server Management Services, we help our Customers to fix SQL related errors regularly.

Let us today discuss the possible causes and fixes for this error.

What is SQL server error 4064?

Each user has a default database. It by default uses this database for login if no other database is explicitly specified. But, what happens if the default database is unavailable at the time of the connection?

This normally triggers the 4064 error message with the message below:

SQL server error 4064

What are the causes of SQL server error 4064?

Microsoft SQL Error 4064 occurs when the default database for a user is dropped. Thus when the user tries to log in, this error shows up. This error will occur whenever the user’s default database is offline as well.

In general, the error 4064 triggers when the user default database is unavailable at the time of connection. It may happen when the database:

1. Is in suspect mode.
2. No longer exists.
3. Is in single-user mode and the only available connection is already being used by someone or something else.
4. Has been detached.
5. Has been set to the RESTRICTED_USER state.
6. Is offline.
7. Is set to emergency status.
8. Does not have the login account mapped to a user, or the user has been denied access.
9. Is part of a database mirror.

Additionally, this may also happen when the login account is a member of multiple groups, and the default database for one of those groups is unavailable at the time of connection.

How to fix SQL server error 4064?

To resolve this error message, we need to specify a valid, available database in the connection string. To prevent the error when the user’s default database is unavailable, log on as a user who can modify logins. Then, change the user’s default database to a database that’s currently available for a connection.

We can use the sqlcmd utility to change the default database. To do this, follow these steps:

  1. Click Start, click Run, type cmd, and then press ENTER.
  2. Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:
    * If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press ENTER:sqlcmd E -S InstanceName d master

    * If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press ENTER:

    sqlcmd -S InstanceName -d master -U SQLLogin -P Password

    Replace the InstanceName in the command above with the name of the SQL Server instance to which you are connecting. Likewise, replace SQLLogin with the SQL Server login whose default database has been dropped and Password with the  SQL Server login password.

  3. At the sqlcmd prompt, type the following, and then press ENTER:ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName

    Replace AvailDBName with the name of the existing database that can be accessed by the SQL Server login in the instance.

  4. At the sqlcmd prompt, type GO, and then press ENTER.
Using SQL Server Management Studio

We can perform this same task via SQL Server Management Studio as well. The steps to perform it include:

  1. Launch SSMS and click on connect to database engine. Enter server name and login details for which you are facing issue.
  2. Now click on Options tab.
  3. You can see Connect to Database option is set to default database.
  4. Now we need to change this default to any accessible database. You need to enter or type the database name.
  5. Now click on connect button to establish the database connection. This time you can connect to your SQL Server instance.
  6. You can bring your database online first or can change the default database for the login. If the database is dropped you need to change the default database of your login.
Change default database of Login Name

Once we have found the database, next step would be to change the default database set for the login. There are two options to change the default database set to any login. One is by using T-SQL code and another is by using GUI. Let’s start with GUI method.

1. Expand Security Folder followed by Logins folder. Now double click on your login name or right click on login and choose properties tab.

2. You can see default database is showing as blank. This was the main issue because your database has dropped from the instance. Now change it to master database and click on OK button to proceed.

3. Now change the connect to database to any existing database on your server like master or msdb

We can use the Alter command to set the default database for the login using the T-SQL method.

ALTER LOGIN [loginname] WITH DEFAULT_DATABASE = master

Replace loginname with your login name.

[Need any further assistance in fixing SQL errors? – We’re available 24*7]

Conclusion

In short, the SQL server error 4064 triggers while connecting to Microsoft SQL Server. This generally happens when the default database is not available to complete the connection requests.  Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

If the user tries to connect to a computer which runs MS SQL but fails to specify the login database while establishing the connection, then the computer uses the default database. Sometimes the default database is not available. And you receive «Cannot open user default database. Login failed. Login failed for user ‘UserName’. (Microsoft SQL Server, Error: 4064)» SQL Server Error message, you cannot open user default database. 

sql database cannot open the default database

Possible Reasons — Cannot Open User Default Database

The user default database is unavailable at the time of connection. The main causes are listed below: 

  • The database is in suspect mode.
  • It is set to emergency status or it is part of a database mirror.
  • The default database (DB) is missing or has been set to the offline, detached or RESTRICTED_USER state.
  • The DB does not have the login account mapped to a user, or the user has been denied access.
  • The DB is in single user mode and the only available connection is already being used by someone or something else.
  • The login account may be a member of multiple groups, and the default database for one of those groups is unavailable at the time of connection.

There are more possible causes that may lead to error code 4064/4062. But the way to repair the SQL Server error remains the same. Read on to see fix SQL database error 4064/4062 and repair the database.

Solutions to Fix the «Cannot Open User Default Database» Error

According to the causes above, the first thing to do is log in another user account that can modify logins and change the user’s default database that is available during the time of connection. Then, specify a valid database in the connection string. If this not working, change the default database.

Solution 1: Change the Default Database in SQL Server 2005 and Later Versions

You can use the sqlcmd utility to change the default database in SQL Server 2005, SQL Server 2000 and SQL Server 7.0. To do this, follow these steps:

For SQL Server 2005 and later versions

Step 1: Click «Start», click «Run», type cmd, and then press «Enter». Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:

1. If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press «Enter»:

sqlcmd E -S InstanceName d master

2. If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press «Enter»:

sqlcmd -S InstanceName -d master -U SQLLogin -P Password

Tip
InstanceName is a placeholder for the name of the SQL Server 2005 instance to which you are connecting.
SQLLogin is a placeholder for the SQL Server login whose default database has been dropped.
Password is a placeholder for the SQL Server login password.

Step 2: At the sqlcmd prompt, type the following, and then press «Enter»:

ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName

Note: AvailDBName is a placeholder for the name of the existing database that can be accessed by the SQL Server login in the instance.

Step 3: At the sqlcmd prompt, type GO, and then press «Enter».

For SQL Server 2000 and SQL Server 7.0

The steps to change the default database seem to be easier for SQL Server 2000 and SQL Server 7.0 users.

Step 1: At a command prompt, type the following and then press «Enter»:

C:>osql -E -d master

Step 2: Type the following and then press «Enter»:

1>sp_defaultdb ‘user’s_login’, ‘master’

Step 3: Type the following and then press «Enter»:

2>go

Solution 2: Use the SQL Database Recovery Software (Professional and Reliable)

In most of the cases, users will repair the database and access it again by following the steps above. What if you still can’t open it? If you are in such a situation, don’t hesitate to try EaseUS MS SQL recovery tool to repair your database.

This software can fix the corruption errors where the inbuilt utilities fail. And the same software resolves the problem in SQL 2005 and also on SQL 2007 and above. Follow the steps to perform a database repair:

Step 1: Select the corrupted database for recovery

  • Launch EaseUS MS SQL Recovery.
  • Select the corrupted database file by clicking «Browse» (the two dots) or «Search».
  • After selecting the file, click the «Repair» button to start the Analyzing process. 

select the SQL database file

Note: To use this software, you need to stop the SQL Server service.

Step 2: Repair the corrupted database

  • The software displays all the recoverable items in a tree-like structure. The items are shown in a left pane.
  • Select the desired component to be recovered. From the window, click the «Export» button. 

Select the database objects

Step 3: Export to the database or as scripts

  • Choose to export the database objects to database or export the items as scripts
  • If you choose «Export to database», enter the information required and choose the target database.

export the SQL database objects

  • A window appears up asking you to provide credentials to connect to the server and the destination to save the recovered items. In order to begin the repairing process, click «OK». 

Note: Before clicking «OK», you need to restart the SQL Server service.

If the user tries to connect to a computer which runs MS SQL but fails to specify the login database while establishing the connection, then the computer uses the default database. Sometimes the default database is not available. And you receive «Cannot open user default database. Login failed. Login failed for user ‘UserName’. (Microsoft SQL Server, Error: 4064)» SQL Server Error message, you cannot open user default database. 

sql database cannot open the default database

Possible Reasons — Cannot Open User Default Database

The user default database is unavailable at the time of connection. The main causes are listed below: 

  • The database is in suspect mode.
  • It is set to emergency status or it is part of a database mirror.
  • The default database (DB) is missing or has been set to the offline, detached or RESTRICTED_USER state.
  • The DB does not have the login account mapped to a user, or the user has been denied access.
  • The DB is in single user mode and the only available connection is already being used by someone or something else.
  • The login account may be a member of multiple groups, and the default database for one of those groups is unavailable at the time of connection.

There are more possible causes that may lead to error code 4064/4062. But the way to repair the SQL Server error remains the same. Read on to see fix SQL database error 4064/4062 and repair the database.

Solutions to Fix the «Cannot Open User Default Database» Error

According to the causes above, the first thing to do is log in another user account that can modify logins and change the user’s default database that is available during the time of connection. Then, specify a valid database in the connection string. If this not working, change the default database.

Solution 1: Change the Default Database in SQL Server 2005 and Later Versions

You can use the sqlcmd utility to change the default database in SQL Server 2005, SQL Server 2000 and SQL Server 7.0. To do this, follow these steps:

For SQL Server 2005 and later versions

Step 1: Click «Start», click «Run», type cmd, and then press «Enter». Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:

1. If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press «Enter»:

sqlcmd E -S InstanceName d master

2. If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press «Enter»:

sqlcmd -S InstanceName -d master -U SQLLogin -P Password

Tip
InstanceName is a placeholder for the name of the SQL Server 2005 instance to which you are connecting.
SQLLogin is a placeholder for the SQL Server login whose default database has been dropped.
Password is a placeholder for the SQL Server login password.

Step 2: At the sqlcmd prompt, type the following, and then press «Enter»:

ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName

Note: AvailDBName is a placeholder for the name of the existing database that can be accessed by the SQL Server login in the instance.

Step 3: At the sqlcmd prompt, type GO, and then press «Enter».

For SQL Server 2000 and SQL Server 7.0

The steps to change the default database seem to be easier for SQL Server 2000 and SQL Server 7.0 users.

Step 1: At a command prompt, type the following and then press «Enter»:

C:>osql -E -d master

Step 2: Type the following and then press «Enter»:

1>sp_defaultdb ‘user’s_login’, ‘master’

Step 3: Type the following and then press «Enter»:

2>go

Solution 2: Use the SQL Database Recovery Software (Professional and Reliable)

In most of the cases, users will repair the database and access it again by following the steps above. What if you still can’t open it? If you are in such a situation, don’t hesitate to try EaseUS MS SQL recovery tool to repair your database.

This software can fix the corruption errors where the inbuilt utilities fail. And the same software resolves the problem in SQL 2005 and also on SQL 2007 and above. Follow the steps to perform a database repair:

Step 1: Select the corrupted database for recovery

  • Launch EaseUS MS SQL Recovery.
  • Select the corrupted database file by clicking «Browse» (the two dots) or «Search».
  • After selecting the file, click the «Repair» button to start the Analyzing process. 

select the SQL database file

Note: To use this software, you need to stop the SQL Server service.

Step 2: Repair the corrupted database

  • The software displays all the recoverable items in a tree-like structure. The items are shown in a left pane.
  • Select the desired component to be recovered. From the window, click the «Export» button. 

Select the database objects

Step 3: Export to the database or as scripts

  • Choose to export the database objects to database or export the items as scripts
  • If you choose «Export to database», enter the information required and choose the target database.

export the SQL database objects

  • A window appears up asking you to provide credentials to connect to the server and the destination to save the recovered items. In order to begin the repairing process, click «OK». 

Note: Before clicking «OK», you need to restart the SQL Server service.

  • Remove From My Forums
  • Question

  • Hi,

    SQL Server 2005 installed on my computer. i was trying to make a login page with VS.2005 pro. But i got some errors on Website Administration Tool. Whatsoever, i registered a database (aspnetdb) . Then, i think i made my default database to aspnetdb. Something went wrong and i decided to delete aspnetdb and start whole procces from the begining and i did it. AAANDD WHOOOLA. I got this error:

    Cannot Open User Default Database, Login Failed
    Microsoft SQL Server, Error 4064

    Is there anyway to change my default database to «master» again? Or simply will i uninstall all the sql server 2005?
    (ıf you say uninstall, answer this:: Will be any problem on VS 2005? I can’t uninstall both :) )

Answers

  • You can resolve this by specifying another database you want to connect to; master, for example. Then you can reset the login’s default database. With sqlcmd, you can do the following:

    sqlcmd -d master -U sa -P mypassword

    and then:

    alter login sa with default_database = master

    Thanks
    Laurentiu

  • I see now that you mentioned that you don’t know sa’s password.

    sa was just provided as an example, for this operation you don’t necessarily need to use sa to connect. You just need to connect with the login for which you’ve received this error. If you use Windows authentication, then you should connect like this:

    sqlcmd -E -d master

    then issue the ALTER LOGIN statement.

    It’s the «-d master» that’s the key here — it specifies that the connection should be made to the master database, so the login won’t try to connect to the database that no longer exists.

    Hope this makes the solution clearer. If you still have problems with resetting the default database, let us know.

    Thanks
    Laurentiu

  • I just ran into the same issue after I dropped a database that was mistakenly set to be the default database. I found the information posted here pointed me in the right direction, but it didn’t really help much because I couldn’t figure out which user should be modified when SQL Server 2005 is configured to use Windows authentication (e.g. trusted connections) exclusively. After a lot of digging through SQL Server Books Online, executing various stored procedures to dump login information, and experimentation, I finally stumbled on the right combination.

    C:> sqlcmd -E -d master

    1> ALTER LOGIN [BUILTINAdministrators] WITH DEFAULT_DATABASE=master

    2> GO

    I show the prompts above so you can see where to type the commands and the expected results (e.g. SQLCMD does not output any information or error messages).

  • You should determine what is the login you are connecting at, then login as administrator and issue an ALTER LOGIN statement to set the default database for that login to master. See Books Online for additional information on using the ALTER LOGIN statement.

    Thanks
    Laurentiu

  • I had the same problem, I was using SQL Server 2005 and deleted the database to which my default Windows Authenticated login maps. (I had my sa password but it would not let me log in using it saying that account was not assocaited with a trusted connection.)

    Anyway, when I tried to connect to the server via management studio it also told me it could not connect because it can not open the default database. So at first I also thought I could not fix this since I could not log in.

    After reading this post, here is how I got around it:

    Run SQL Server Management Studio, and on the initial «Connect To Server» dialog box, click «Cancel». Now under your regsitered server list, find the local server, right click on it and select properties. Go to the connection properties tab and enter «master» for «Connect to Database:». Now save it, and voila, you can connect again!

Today, I got Microsoft SQL Server error 4064 while I was trying to connect to my SQL Server Instance using my login id techyaz. Read this article to fix this SQL Server error 4064. The error text of this error is “Cannot open user default database. Login failed.” This solution is apply to both SQL logins as well as windows logins. The error details are given below:

Cannot open user default database. Login failed.
Login failed for user “techyaz”. (Microsoft SQL Server, Error: 4064)

Related Articles:

  • Fix 15170: Logins owns one or more Agent Jobs
  • How to fix error 15434: Could not drop login as the user is currently logged in
  • Error Code 15174: Login ‘xxxyyy’ Owns one or more databases(s). Change the owner of database(s) before dropping the login.

Microsoft SQL Server Error 4064

SQL Server Error 4064 generates because the default database set for your login has been dropped or becomes inaccessible by any reason. Whenever we create any SQL Server or windows login, we mention a default database. If you don’t mention any database during login creation then SQL Server set default database as master database.

You might also get this error on secondary replica of AlwaysON Availability Group because that database on secondary replica remains into inaccessible mode. So, don’t do any changes if you are getting this error in AOAG environment. You just need to connect to the primary replica because it is designed to keep secondary replica database into inaccessible mode.

Here, we had a database named “TechyazDB” that was set as default database for my login techyaz. This database was dropped by someone and when I tried to connect to SQL Server, it gave me below Microsoft SQL Server error 4064 because database was not there on SQL Server instance. Below is the screenshot of Microsoft SQL Server error 4064 that is clearly saying “Cannot open user default database. Login failed.”

error 4064

Solution

There are two solutions to fix this issue. Either make your database online by restoring it or by anyway or change the default database of this login to master or any other database that is online on the instance. As you cannot bring your database online because you can’t connect to the instance so your first option is to connect to the instance.

If you have other DBAs or sysadmin accounts, you can connect using those accounts to SQL Server and change the default database for your login to master and then you can make database connection.

Let’s consider only you are the admin on this instance so how will you fix it. Follow below steps:

Launch SSMS and click on connect to database engine. Enter server name and login details for which you are facing issue.

connect to database engine

Now click on Options tab of above image. You will get below screenshot.

click on options tab of connect database window

You can see Connect to Database option is set to default database that was TechyazDB for this login. Now we need to change this default to any accessible database. It will not allow you to select from drop down. If you will browse the database it will give you same error. You need to enter or type the database name. I typed as master database as shown in below image.

change default database in connection property

Now click on connect button to establish the database connection. This time you can connect to your SQL Server instance.

Now, it’s your wish whether you want to bring your database online first or you want to change the default database of your login. Generally, if database has been dropped as a planned activity then you need to change the default database of your login. Read below section to know how to change default database of your login.

Change default database of Login Name

There are two options to change the default database set to any login. One is by using T-SQL code and another is by using GUI. Let’s start with GUI method.

As you have connected to your SQL Server Instance. Expand Security Folder followed by Logins folder. Now double click on your login name or right click on login and choose properties tab. You will get below property window.

login property

You can see default database is showing as blank. This was the main issue because your database has dropped from the instance. Now change it to master database and click on OK button to proceed.

change default database in login property window

Second method is T-SQL method. Run below ALTER command to set the default database of your login.

--Change techyaz with your login name.
ALTER LOGIN [techyaz] WITH DEFAULT_DATABASE = master

Below is the screenshot of this command.

T-SQL code to set the default database for a login

Related Articles:

  • Fix Error 15173: Revoke the permission(s) before dropping the login
  • How to fix error 15141: The Server Principal owns one or more endpoints.
  • How to fix error 15138 and Error 3729

Here, I have explained step by step solution to fix SQL Server error 4064: Cannot open user default database. I hope you like this article. Please follow our Facebook page and Twitter handle to get latest updates.

  • Author
  • Recent Posts

Manvendra Deo Singh

I am working as a Technical Architect in one of the top IT consulting firm. I have expertise on all versions of SQL Server since SQL Server 2000. I have lead multiple SQL Server projects like consolidation, upgrades, migrations, HA & DR. I love to share my knowledge. You can contact me on my social accounts for any consulting work.

Manvendra Deo Singh

Summary

Fix Error 4064: Cannot open user default database. Login failed.

Article Name

Fix Error 4064: Cannot open user default database. Login failed.

Description

Today, I got this error 4064 while I was trying to connect to my SQL Server Instance using my login id techyaz. Read this article to fix this error. This solution is apply to both SQL logins as well as windows logins.

Author

Manvendra Deo Singh

Publisher Name

www.techyaz.com

I am using an SQL database where I have seen the database connection lost when connecting to the server many times. This query is most common when connecting to the database server. So, here in this tech guide, we will explain all about Microsoft SQL server error 4064 Cannot open user default database and also how it can be resolved. This guide comprises of reasons behind the database error 4064, solutions for this error and at last a third-party solution.

Every user has a default account-related database in SQL Server. Each time the user attempts to sign in without specifying a password, the default database remains active. But if the default database is not available, or the SQL Server does not locate the server, the issue will be shown with an error message.

Error:

“Cannot open user default database. Login failed.

Login failed for user “username” (Microsoft SQL Server, Error: 4064)

SQL Server Error 4064”

When you double-click the user (Expand Security-> Logins) you will end up seeing that Default User is not allocated a user as shown below.

Reasons for the occurrence of Server Error 4064:-

There are many more explanations for the error such as the unavailability at the time of communication of the user default server. It may be that the database is in suspicious mode or offline. There is also the possibility that it was set to or left disconnected from RESTRICTED USER. The number of causes could be the following:

  1. RESTRICTED USER: Limiting access to databases by general users is important when performing certain maintenance tasks, particularly in recovery situations. Limited access mode can be used in such circumstances to restrict connections to high-level users only.
  2. There is no longer any database: When there is no database present then it may result in server error 4064.
  3. The database is set to the stage of an emergency situation: When a database is placed in the state of emergency, three major changes are made to the database configuration:
    • Makes the database READ ONLY
    • Restricts access to representatives of the set server feature only
    • Logging is disabled (as the database is READ ONLY)
  4. It operates in single-user mode: It shows that only one user can connect to the server.

Because of the above-mentioned reasons, Microsoft SQL server error 4064 occurs. So, to solve this blunder “cannot open default user database” we are going to explain various methods in detail.

Solution 1: Connect to Server

Specify the name of the server as TempDB for Connect to Server in the Connection Properties and press the Connect option to connect to the SQL Server.

Upon connection with the SQL Server Instance, execute the TSQL below to add a new default server to the account.

Use master

GO

ALTER LOGIN [MonitorDB] WITH DEFAULT_DATABASE = TempDB

GO

Solution 2: Connect to Different Database

You can log in to your account if you are the Database Administrator and switch the default server to the master server. Follow the steps below:

  1. Begin the Studio for SQL Server Management. When the wizard ‘ Connect to Server ‘ opens, enter the name, username, and password of the database. Tap on the Options tab here.
  2. Look “Connect to database” option which is connected to the user account’s default server. After this, you can type any database name that is accessible or write the master database name as well.

    NOTE: Do not pick any other server by using the drop-down as it may send the error.

  3. Tap the Connect key to sign in successfully this time.

Solution 3: Change the Default Database

You can also use the login properties to change the default database to any other database. Follow the steps below:

  1. Go to Security Folder and expand it after connecting to your SQL Server case. Select the folder and go to your login name. Tap the name of the account right click on Property.
  2. You can see the ‘ default database ‘ option in the bottom part. If it is empty, this means that the account has not associated with your default folder. Type the name of the database that is accessible and then click on the OK button.

You can also execute the T-SQL command to alter your SQL account’s default server. Follow the instructions:

“ALTER LOGIN [username] WITH DEFAULT_DATABASE = master”

Methods mentioned above can be said to fixing Microsoft SQL server error 4064. But the problem arises when a database is accessible by the user. Then a third party utility comes named SQL Recovery that is capable to recover inaccessible files of any server. Also, it can easily recover damaged databases quickly.

Download Now

Conclusion

This guide has been discussed all the effective measures for solving the server error 4064 in the SQL database. With manually and alternatively both the solutions have been described above. So, users can use any one of the options whether working step by step manually or directly go with SQL Recovery utility.

Best Method To Resolve “ Cannot Open User Default Database Error 4064” In SQL Server

It is an obvious fact that SQL saves a default account-related database in its server automatically. While the user attempts to sign in without specifying a password, the default database remains active. But sometimes MS SQL login is not able to connect to the server, then the user encounters an error message on screen which is  “Error 4064 in SQL Server”.

Error Message

While using MS SQL user who has an account in the concerned server owns a database by default. Might be connection fail if the default database is also unavailable at the time of the linkage. Therefore, you encounter that a SQL Server error 4064 is received. 

The exact error message is written below and find the image of the error which is received by random users.

Cannot Connect to USER.

Cannot open user default database. Login failed.

Login failed for user “username” (Microsoft SQL Server, Error: 4064)

SQL Server Error 4064”.

sql server error 4064 error message

It is very frustrating, while you have some urgent work on MS SQL and you encounter this error but you need not worry. In this article, we will offer you the best method to resolve SQL server error 4064 login failed for user. 

Possible Reasons for Receiving Error 4064 in SQL Server

There exist a lot more reasons for the error, such as due to unavailability of the user default database at the time of connection.  

Other variety of cause may be as follows that :

  1. You might end up receiving this error when a Windows or SQL Server Login is not able to connect to the default database which is assigned to the user.
  2. There is no longer any database present.
  3. The login account may be a part of multiple groups and the default database for one of the groups is occupied at the time you want to create a connection.
  4. The database doesn’t have an account login mapped to a user.
  5. The user has been deprived of access.

Learn How To Resolve Error 4064 in SQL Server

Repairing this error is really easy so you can try again to login with that user but first before to Connect, you must go to the Options and you will be asked for the Connection Properties on the second tab of the login dialog box and you must enter the master database in the drop-down box, see the figures to understand quickly.

To get rid of the error we offers you an organic method, you need to just follow these mentioned steps:

  • Initially, click on Option>> Button of “Connect to Server”.
  • Now change the connect to database to any server like master.
  • In the dialog box, select Connect and it will successfully log you in. After login to the system run the following statement for your username and it should fix your problem. Make sure to replace [test] with your username and master with your database name.

              ALTER LOGIN [test] WITH DEFAULT_DATABASE = master

The method mentioned above can be said to be the best one for fixing Microsoft SQL server error 4064. But the problem arises when a database is not accessible by the user. Then you can use an alternate method which is a professional tool named SQL Recovery, capable to recover inaccessible files of any server. Also, it can easily recover damaged databases quickly. 

Bottom Line

We have discussed both manual and alternate methods to resolve “Cannot Open User Default Database Error 4064” in the SQL server. But there are some limitations to the manual method as it cannot recover a SQL file that is inaccessible. Also, the manual method required a person who is technically sound. So we recommend you to use an alternate method which SQL Recovery software which is designed to restore the SQL database in one go. It is a direct method for recovery and no need for technical expertise. Hopefully, you found this article useful to resolve your problem of Error 4064 in SQL Server

Related Post

Понравилась статья? Поделить с друзьями:
  • Sql server 3415 error
  • Sql server 2012 installation error
  • Sql rise error
  • Sql provider ssl provider error 0
  • Sql parse error eof in string detected