User has lost Login Name

Hello all. We have a Citrix database with a server login called Citrix_User, and User in that database with the same name. I had to restart the server yesterday to swap some drives. Today when I go to the properties of Citrix_User in the database the login shows <none>. When I try and delete that user it says "The selected user cannot be dropped because the user owns objects". Can you guys tell me how to both get that login back and how to delete the user account (I've created another one that Citrix is now using, but need to know in case that happens again).  Thanks, Jordan
JordanKingsleyAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
Hi JordanKingsley,
in order to change the ownership of the objects you can use the following

DECLARE @old sysname, @new sysname, @sql varchar(1000)
SELECT @old = 'Citrix_User' ,
@new = 'dbo' ,
@sql = ' IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES WHERE QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?'' AND TABLE_SCHEMA = ''' + @old + ''' )

EXECUTE sp_changeobjectowner ''?'', ''' + @new + ''''EXECUTE sp_MSforeachtable @sql


then try to recreate the login
0
 
JordanKingsleyAuthor Commented:
I'm sure I understand what that did. How do I delete that user?
0
 
PSSUserCommented:
In order to be able to log in with the user you should just need to set the (default) database to a valid database. This normally gets set to none if the database that was originally the user's default database has been dropped. This includes if the database was dropped and re-created.
0
 
JordanKingsleyAuthor Commented:
I see, but how to I delete a user that I don't need anymore and I still get the message:

"The selected user cannot be dropped because the user owns objects"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.