If the user attempts to connect to a computer running MS SQL without specifying the login database, the computer defaults to a database, which may not be available, resulting in a "Cannot open user default database. Login failed. Login failed for user 'UserName'." error message.
The user default database is unavailable at the time of connection due to various reasons. This can be caused by a database server being down, a network issue preventing access to the server, or a problem with the database itself, such as a corruption or a configuration issue. Additionally, the user's permissions or credentials may not be valid, or there may be a conflict with another database or application.
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. To fix SQL database error 4064/4062 and repair the database, you can try running the DBCC CHECKDB command to identify and repair any database errors. This command can help detect and correct errors in the database, including those that may be causing the 4064/4062 error code. By running DBCC CHECKDB, you can potentially resolve the issue and get your database back to a healthy state.
To resolve the issue, log in to another user account that has the necessary permissions to modify logins, and change the default database available during connection. Then, specify a valid database in the connection string. If this doesn't work, try changing the default database.
To change the default database in SQL Server 2005, SQL Server 2000, and SQL Server 7.0, use the sqlcmd utility. Follow these steps:
For SQL Server 2005 and later versions
Step 1: To reset a SQL Server login password, start the Command Prompt, navigate to the SQL Server installation directory, and use the sqlcmd utility to execute the ALTER LOGIN statement. The command to reset the password is: ALTER LOGIN [username] WITH PASSWORD = [new password]. Replace [username] and [new password] with the actual username and new password.
1. To connect to SQL Server using Microsoft Windows authentication, type the following command at the command prompt and press "Enter":
sqlcmd E -S InstanceName d master
2. You can create a SQL Server login using the SQL Server Management Studio (SSMS) tool. To do this, follow these steps:
sqlcmd -S InstanceName -d master -U SQLLogin -P 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 an 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
For users familiar with SQL Server 2000 and SQL Server 7.0, changing the default database appears to be a relatively straightforward process.
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
If you're unable to open your database after trying the steps above, don't worry! You can try using a Qiling MS SQL recovery tool to repair your database. This tool can help you recover your database even if you've tried the usual troubleshooting steps. Just remember to follow the instructions carefully and you might be able to get your database back up and running in no time.
This software can fix corruption errors where inbuilt utilities fail, resolving the issue in SQL 2005 and above, and can be used to perform a database repair by following steps.
Step 1: Select the corrupted database for recovery
Note: To use this software, you need to stop the SQL Server service.
Step 2: Repair the corrupted database
Step 3: Export to the database or as scripts
Note: In order to proceed, you must restart the SQL Server service before clicking "OK".