Orphaned SQL login in replicated db

  • Hi,

    I'm using log shipping to replicate a DB to another server. This replicated db is used for reporting. There is a SQL login "test" on the primary server mapped to the replicated db but I noticed that this same user is not mapped on the secondary db. The login exists on the secondary server but the properties show that it is not mapped to the secondary replicated db. This is preventing this login from reporting against the replicated db. As a troubleshooting step, I brought the secondary db out of standby and noticed that this login "test" was orphaned. I thought that since the login was mapped on the primary wouldn't this replicate to the secondary? I have tried configuring replication again from scratch several times to see if there was something I missed but can not find out why this is. Any ideas?

    Thanks,

    TKE402

  • I don't know if it applies to replication, but check out sp_change_users_login

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Look up this procedure, sp_change_users_login, in BOL and run it on your other system (hopefully). Using log shipping, I'm not sure you will be able to, but worth a shot.

  • thanks for the replies.

    I tried the orphaned users resolutions and this account did show as orphaned but after running EXEC sp_change_users_login 'Auto_Fix', 'user' the account still does not have the secondary replicated db as a mapping in the login properties in SSMS. Any other suggesstions?

    Thanks,

    TKE402

  • tke402-837787 (2/18/2010)


    thanks for the replies.

    I tried the orphaned users resolutions and this account did show as orphaned but after running EXEC sp_change_users_login 'Auto_Fix', 'user' the account still does not have the secondary replicated db as a mapping in the login properties in SSMS. Any other suggesstions?

    Thanks,

    TKE402

    Stop, breathe. Can the user login and access the database?

  • No the login in question can not access this particular DB. It has access to the other replicated dbs on this secondary server.

  • At a lose right now. I had a glimer of an idea but it fled away into the desert (inside joke).

    If I can think of anything I'll pop back in.

  • Post the output of sp_helpuser 'username' after u run it under the db in question.

  • Thanks for the replies. Here are the results:

    username groupname login name DefDBName DefSchemaName UserID SID

    test, public, test, usersdb, users , 12 ,0xE247C7..........

    When I run this on the primary server I get two entries:

    username groupname login name DefDBName DefSchemaName UserID SID

    testdb_datareadertestusersdb Select_All_Tables 130x03B9...

    testSelect_All_Tablestestusersdb Select_All_Tables 13 0x03B9...

  • tke402..

    run below command on your replicated DB

    EXEC sp_change_users_login 'Update_One', 'UserName', 'LoginName'

    Theory:

    When you restore DB only users are replicated not Logins....that is one of the reason of Orphaned users in the DB.

  • Try this script.

    -- Drop the working table if it already exists

    IFOBJECT_ID('tempdb..#tblUsers') IS NOT NULL drop table #tblUsers

    GO

    -- Get the users into a working table. Code is non-destructive if any of

    -- them don't happen to be orphaned.

    SELECTIDENTITY(int, 1,1) AS RowNumber,

    s.name

    INTO#tblUsers

    FROMsysusers s

    WHEREsid IS NOT NULL AND sid NOT IN (0x00, 0X01)

    -- Set up the number of times to loop

    DECLARE@RowCounter INTEGER

    DECLARE@TheUserName VARCHAR(255)

    DECLARE@WorkingString NVARCHAR(255)

    SELECT@RowCounter = COUNT(*) FROM #tblUsers

    -- Now, loop through each user and link 'em up

    WHILE@RowCounter > 0

    BEGIN

    SELECT@TheUserName = name

    FROM#tblUsers

    WHERERowNumber = @RowCounter

    SELECT@WorkingString = 'sp_change_users_login

    @Action = ''Update_One'',

    @UserNamePattern = ''' + @TheUserName + ''',

    @LoginName = ''' + @TheUserName + ''''

    EXECUTEsp_executesql@WorkingString

    SET @RowCounter = @RowCounter - 1

    END

    PRINT'Done!'

    EnjoY!
  • thanks for the replies. I did as you said but still no dice. I checked the SQL login properties through SSMS and the mapping to the replicated db is still unchecked. I can not manually add a check through SSMS because I get an error saying that the db is in read only mode.

  • Thanks SSC-Enthusiastic

    I ran the script on the secondary server master db and received a bunch of errors:

    Terminating this procedure. The User name 'db_accessadmin' is absent or invalid.

    Msg 15291, Level 16, State 1, Procedure sp_change_users_login, Line 108

    Terminating this procedure. The User name 'db_owner' is absent or invalid.

    Msg 15291, Level 16, State 1, Procedure sp_change_users_login, Line 108

    Terminating this procedure. The User name 'DOMAIN\GROUP' is absent or invalid.

    I then ran it against the replicated db and I get the same error messages except the additional mention that the db is in read only mode:

    Terminating this procedure. The User name 'db_accessadmin' is absent or invalid.

    Msg 15291, Level 16, State 1, Procedure sp_change_users_login, Line 108

    Terminating this procedure. The User name 'db_owner' is absent or invalid.

    Msg 3906, Level 16, State 1, Procedure sp_change_users_login, Line 123

    Failed to update database "DB" because the database is read-only.

  • Can you please run this, i believe this SQL 2005 instance.

    select name, is_read_only, state_desc from sis.databases.

    If you see is_ready_only column value as '1' for the DB you have issue, Do this.

    alter database Databsename set read_write with rollback immediate, it should fix.

    EnjoY!

    EnjoY!
  • Hi,

    The DB is a replicated db due to log-shipping. Isn't it supposed to be in read only standby mode? This is the error I get:

    Database 'DB' is in warm standby. A warm-standby database is read-only.

  • Viewing 15 posts - 1 through 15 (of 19 total)

    You must be logged in to reply to this topic. Login to reply