
And if you try to connect using Enterprise Manager (again, SQL Server 2000), you'll get this:

If you don't have another account to connect with, you may think you're stuck, but you're not. Thankfully, isql (not isqlW) will see the error and force the connection to the master database instead. For instance, a connection using isql where the default database no longer exists will result in the following:

In SQL Server 2005, if the login doesn't have permission to access the database, you'll see this error message:

On the other hand, if the database doesn't exist (as was the case with the SQL Server 2000 example), you'll see an error similar to the following.

In SQL Server 2005's SQL Server Management Studio, however, there is an option to choose what database to connect to. If you click on the Options >> button, a second tab appears. There, enter master for the database to connect to (highlighted below).

Once you've established a connection to the SQL Server where you can execute a query, here is where the system stored procedure sp_defaultdb is your friend. Reset the login's default database like so:
EXEC sp_defaultdb 'MyLogin', 'master'If you want to go with the new SQL Server 2005 syntax:
GO
ALTER LOGIN MyLogin
WITH DEFAULT_DATABASE = master
GO
Technorati Tags: T-SQL | SQL Server | Microsoft SQL Server | SQL Server 2000 | SQL Server 2005



Subscribe to this blog
Briefcase
Print
No comments.