August 27, 2009 at 2:15 pm
I have had this problem for years and never bothered to ask about it, but it's causing big problems today.
Moving a database from old server to new. Win2k/SQL2k to Win2003/SQL2005.
I have tables, view and SPs but need to copy users over. Some were already brought over before I started working here. In MSMS, I expand the tree on the left, open Security/Logins. I try to add a new login. When I set everything correctly, I click OK, and it tells me the login already exists. Which is completely false, buy the way. This has happened pretty much 100% of the time I have ever tried to add a login.
So this time, I download the 14-day trial of the Redgate compare tool. It shows the users on the left which don't exist in the new server on the right. I let it generate a script for me. The relevant part for one of them is (the x's are mine):
IF NOT EXISTS (SELECT * FROM master.dbo.syslogins WHERE loginname = N'shipauto')
EXEC sp_addlogin N'shipauto', 'xxxx'
GO
EXEC sp_grantdbaccess N'shipauto', N'shipauto'
GO
I run it, and get this error:
Msg 15023, Level 16, State 1, Line 1
User, group, or role 'shipauto' already exists in the current database.
That statement is completely wrong. I have looked in the list of users, logins, roles, and everywhere else, and it's just completely wrong. This happens every time I try to create a new user, even going back to my SQL 2000/ASP days.
August 27, 2009 at 2:22 pm
Have you checked for the users in the database? Not just the security. Go in that particular database you are trying to give access to that particular user, under security check the users and see if that user is already there?
August 27, 2009 at 2:36 pm
Yeah, that's what I meant. I checked in both the security section for the desired database and the main security folder.
Having said all that, I just discovered they are in the master database listed under users. Doesn't make any sense. And my programs still don't work.
August 27, 2009 at 2:43 pm
and just as important, why would redgate generate code that doesn't work?
August 27, 2009 at 3:19 pm
A possible reason for the redgate question stems from the users existing in a database. It seems that the users it sees might be orphaned and so it is trying to use the wrong sids. Have you tried to fix orphaned users or remove the users from the master database? It would seem that they should only be in the applicable user databases and not the system databases.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
August 27, 2009 at 3:20 pm
This can happen if you have orphaned users and try to use the GUI, it gets confused. Usually works fine via query window so run all your create logins via a query window using the create login statement.
In the database itself run sp_helpuser or select * from sysusers to see what users are actually defined within the database. those with a NULL in the login column (think its called that) are likely orphaned. Run sp_change_users_login 'report' to confirm this and match them to logins you created to fix them.
If you use sp_help_revlogin (the version designed for SQL2000 to 2005) to transfer your logins these problems should not arise.
---------------------------------------------------------------------
August 28, 2009 at 7:47 am
A couple of problems with that:
1. The users didn't exist in Master until I ran that script which told me they were already in existence.
2. When I tried to drop them, I got an error saying the user was tied to a schema. I'm afraid to say go ahead and drop the schema at this point.
August 28, 2009 at 8:01 am
george sibbald (8/27/2009)
This can happen if you have orphaned users and try to use the GUI, it gets confused. Usually works fine via query window so run all your create logins via a query window using the create login statement.
I thought the code pasted in my first post did exactly that.
In the database itself run sp_helpuser or select * from sysusers to see what users are actually defined within the database. those with a NULL in the login column (think its called that) are likely orphaned.
I did and couldn't see any column that might be the one you referred to. The only ones which had a NULL value for some rows in the results set were sid, altuid, and roles.
Run sp_change_users_login 'report' to confirm this and match them to logins you created to fix them.
I ran this and got an empty set, whether I ran it from both the real db and from master.
If you use sp_help_revlogin (the version designed for SQL2000 to 2005) to transfer your logins these problems should not arise.
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'sp_help_revlogin'.
August 28, 2009 at 12:45 pm
sp_help_revlogin -
http://support.microsoft.com/kb/246133
as for NULL value, its the Loginname value returned in sp_helpuser, can point to an orphaned user if its NULL.
---------------------------------------------------------------------
August 28, 2009 at 12:49 pm
as for NULL value, its the Loginname value returned in sp_helpuser, can point to an orphaned user if its NULL.
In which field, though?
August 28, 2009 at 1:48 pm
column loginname
---------------------------------------------------------------------
August 28, 2009 at 10:28 pm
Here is an article that may also be of use:
Fixing Orphaned Users - Recreate Scenario
User Owns Schema and is Orphaned
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply