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:
- 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:
- 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. - 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. - 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:
- At a command prompt, type the following and then press ENTER:
C:\>osql -E -d master
- At the osql prompt, type the following and then press ENTER:
1>sp_defaultdb 'user's_login', 'master'
- At the second prompt, type the following and then press ENTER:
2>go