views:

462

answers:

1

Hi,

I'm attaching a new database programatically using VB.net application. I wrote DB scripts and execute them using command object. After attaching the db, I have to create logins and add roles. If the login am going to create is already existing on that target SQL server then am just adding the roles using (EXEC SP_addrolemember), problem starts here. Role gets added to the User but it only shows in the db that I have just now attached. ie-

In management studio -> Databases -> ((newly attached database)) -> Security -> Users

but its not added in the main SQL server, ie -

In management studio -> Security -> Logins -> ((user name))

When I double click the username in the main sql server logins under "User Mappings", I dont find the roles appended. Its updated only under the database I have attached. Due to this when I try to open the newly attached database using the existing user credentials then it says access denied to the newly attached database!!

Is there any way around this problem??

Thanks in advance

Sai

+1  A: 

I had similar issues where I restored a db with a user included and there was a conflicting user under sql security. I found this Link provided the answer.

Tanner
Thank you Tanner...that solves my problem. But I see another problem(maybe minor one for now).. SP_Change_users_login is going to be deprecated from future versions of SQL then same prob arises...:-(
As developers we can only deal with one problem at a time ;-)
Tanner