سؤال

This is related to my previous post..

Differential Backup Issue - Why? Is this Possible?

Basically, the issue which I am having now is that in my restore process (as part of ETL), there are tasks to re-map db users to logins (because they are SQL Auth users in server A so lose mapping when restored on server B). Since restore with STANDBY will not allow this as it will be read-only db.. how can I get around this..?

هل كانت مفيدة؟

المحلول

Your users from db on server A will be moved to the database on server B with the backup. Then all you need is to recreate the logins with the same sid. You do this using WITH SID option:

CREATE LOGIN My_login WITH SID = 0x14585E90117152449347750164BA00A7

the sid obviously is your user sid that you can find in sys.database_principals:

select name, sid
from sys.database_principals
where type_desc = 'SQL_USER';

نصائح أخرى

I find it easier to transfer logins via dbatools.io Copy-SQLLogin cmdlet if PowerShell is an option or sp_help_revlogin if not.

The Copy-SQLLogin cmdlet is a much easier approach and that link even has a video to help you step through the process, but again, if PowerShell isn't an option and you need to go the sp_help_revlogin route, make sure you execute that stored procedure (after you create via the linked article) on ServerA, copy the login statements over to ServerB and run the statement(s) there.

If you get an error, you may need to drop the existing user from ServerB first so that you can sync up the SIDs.

Finally, if you're running SQL 2012 or later, you may be able to configure your database to be a partially contained database instead. This will short-circuit things so the security is transferred with the backup as security is handled at the database level and not at the instance level. There are limitations to using partially contained databases, so review those first if you feel like this may be the approach you wish to take instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى dba.stackexchange
scroll top