Monday, August 21, 2006

Cannot open database requested in login 'databaseName'. Login fails

it happened to me with sql server 2000 and 2005, after restoring the database i couldn't login from asp or asp.net script.
this solution is for sql 2000 but i think it will work also with 2005.
i noticed that after the restore the user that i'm tring to loggin with appears on the logins of the specifice database but the culomn of Login Name is empty. i looked at the same place in the original database and i saw something there... it was lost with the restore! i don't know if it's a bug or what, but i lost few days of fighting with it!
anyway, you need to put the the user name... it's not so easy, i didn't find the way to do it, i had to delete it and add it again.. that also not so simple! so you can delete the login it shouldn;t own nothing... so i had to change all the objects that were owned by this login and then could do it!!
i hope you found this blog before losing too much time on this!! the time that i spent is enough :)
if that helped you so write a commemnt
have a nice programming!!

Discuss Post

7 comments:

Anonymous said...

Did you try sp_change_users_login

Anonymous said...

I ran into this problem after I moved a SQL Server 2000 database to a SQL Server 2005 server. I had detached the tables on the 2000 server, copied the files to the 2005 server and attached them there. Whenever I tried to connect to the database on the new server using my login, I received the error message.

My solution was to run this: EXEC sp_change_users_login 'Update_One', 'Bob', 'Bob'
('Bob' is the login that I was having trouble with). The problem went away...

Anonymous said...

Thank you!!! sp_change_users_login did the trick of adding the login name back into the user. This is the only page I could find on the Internet that was even close to what I needed. You saved me a couple of days, I'm sure.

RamiX said...

i'm happy to know, well, i thought about you when i wrote this post :)

Anonymous said...

Wow thanks dude!! We've been at this for a the past 6 hrs!!

Anonymous said...

Thanks very much. I was having the same issue and your solution worked.

Anonymous said...

You saved me many hours of frustration - thank you so much!