|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
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.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, October 26, 2012 11:23 PM
Points: 91,
Visits: 406
|
|
| 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?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
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.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
| and just as important, why would redgate generate code that doesn't work?
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 6:30 PM
Points: 18,733,
Visits: 12,330
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:24 AM
Points: 5,265,
Visits: 11,194
|
|
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.
---------------------------------------------------------------------
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
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.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
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'.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:24 AM
Points: 5,265,
Visits: 11,194
|
|
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.
---------------------------------------------------------------------
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, September 09, 2010 7:58 PM
Points: 121,
Visits: 195
|
|
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?
|
|
|
|