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:
- Click Start, click Run, type cmd, and then press Enter.
- 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.
- 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.