SQL Server "cannot open user default database, Login Failed" Troubleshooting

Source: Internet
Author: User

Each user has a default database. When you connect to a computer running Microsoft SQL Server, if you do not specify to log on to the database, the default database is used. However, if the default database is unavailable during connection, the connection may fail. In addition, you will receive error message 4062 or error message 4064. The original texts of these error messages are as follows:

The default user database cannot be opened (cannot open user default database)

The solution is as follows:

In SQL Server 2005, you 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 based on the authentication type used for SQL Server login:
    • If SQL Server is logged on to connect to the instance using Microsoft Windows authentication, type the following at the command prompt and press Enter:

      Sqlcmd-e-s InstanceName-D master
    • If you log on to SQL Server and use SQL Server authentication to connect to this instance, enter the following content 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 be connected. Sqllogin is a placeholder for deleting the SQL Server Logon of its default database. Password is a placeholder for the SQL Server login password.

  3. Enter exec sp_defaultdb 'sa 'and 'master' to change the default database, where "sa" and "master" are based on the actual situation. Press enter and enter go and press Enter.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.