Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 945
  • Last Modified:

default db no more- how to recover

is this query good to find which logins have default database that is no more
select * from master..syslogins where dbname not in (select name from sysdatabases)

how do you recover from situations like these?
0
anushahanna
Asked:
anushahanna
3 Solutions
 
mordiCommented:
Hi,
It is not clear what happened.
If you have any backup of the missing database so after restore all the users get restored also.
0
 
anushahannaAuthor Commented:
but that is login info, won't be in database.
0
 
BrandonGalderisiCommented:
I've written a write up on how to recover from a situation where you can't login due to a missing default database.

http://www.sqlservernation.com/home/fix-for-cannot-open-user-default-database-login-failed.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lcohanDatabase AnalystCommented:
Yes that should do it as the default db is stored in syslogins.dbname - from http://msdn.microsoft.com/en-us/library/ms178593.aspx

"dbname
 sysname
 Name of the default database of the user when a connection is established."
 
--slightly updated
select name,dbname from master..syslogins where dbname not in (select name from master..sysdatabases)
0
 
geek_vjCommented:
>>is this query good to find which logins have default database that is no more
select * from master..syslogins where dbname not in (select name from sysdatabases)

Yes, the query is fine

>>how do you recover from situations like these?
In that case, you have to login using another user and change the default database of the login which is having issue.
0
 
anushahannaAuthor Commented:
thanks for your helpful input.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now