SQL Server – Dropped my default database
Posted: Friday, July 18, 2008 8:14 PM
by
dan
Today I learned an important lesson about Sql Server 2005, don’t change your default database unless you absolutely have to. I set mine to DatabaseX and then I promptly dropped DatabaseX. When I tried to log in I got a nice error message
Cannot Open User Default Database, Login Failed
I didn’t setup the VM that I was using, so I didn’t know the SA password. I basically had no way to get back into the server. So if you ever find yourself in this predicament, execute the following from the command line:
C:\> sqlcmd -E -d master
1> ALTER LOGIN [YOUR USER NAME HERE] WITH DEFAULT_DATABASE=master
2> GO
That will reset your default database back to master and you can login again.