User Mapping script

  • Hi,

    I have to drop and re-create a DB nightly.

    When I do that my user loses it's mapping (read_only) to that DB.

    Is there a way to create a script (that I can schedule as a job) that will recreate the read only mapping to that Db?

  • got it myself thanks anyway...

    CREATE LOGIN [UserA] WITH PASSWORD=N'UserA',

    DEFAULT_DATABASE=[OrphanedUsers],

    CHECK_EXPIRATION=OFF,

    CHECK_POLICY=OFF

    GO

  • oh wait that's not gonna work that user already exists....

  • I assume you're adding the user back manually every day ? Take that script and put it into a new job, then schedule to run at the appropriate time after the database is created.

    SQL ServerAgent -> Jobs -> <right click> NewJob

  • I'm creating only the DB mapping, the user is still there.

    the mapping to the dbis what goes away

  • if the user exists in the DB which you just restored,

    you can schedule a job to run this after you restore DB

    EXEC sp_change_users_login 'update_one', @username, @username

Viewing 6 posts - 1 through 5 (of 5 total)

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