In the process of off-lining a database for backup I lost connection, the only user I had details for was set to use the database which I had just off-lined (thankfully not the master
database) as the default database...problem as you can see.
In looking about on stack overflow I was unable to find a solution for my problem.
After a bit of digging about I remembered the command-line tool sqlcmd
.
Well the solution to the problem was pretty straightforward:
Start->Run->cmd
then hit Enter
)sqlcmd -S myserver\sqlexpress -d master -U myusername -P mypassword
which starts a command-line connection to the database specified after -d
-s/-S
, -d/-D
, -u/-U
and -p/-P
are not interchangeable.alter login myusernamehere with default_database = master
to set the default database for your user to mastergo
and press enter
. . . and that should be your user set to using the master
database as its default database to connect to. It should appear on-screen to look like this:
And that should be you set. I know this is an unlikely scenario for most, but should it happen to you, hopefully this will be of some use in restoring your normal access and getting the database back on-line.
The other option is to click the "Options" button when logging into SSMS. There, you can specify which database to connect to. So as long as you have access to one of the other databases, such as master, you should be able to connect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With