Sql-server – Mapping an MSSQL Login to the secondary replica in a High Availability Group

loginsSecuritysql server

I'm trying to map a login to a user in a database on the secondary replica of a two node High Availability group. Obviously this fails since the replica is offline. Is there a way for me to create the login mappings to users to the offline database? I'm using Windows domain accounts BTW, so no SID issues, just the mapping problem.

When connecting to the secondary, after a failover, the error is that "the users' default database could not be accessed." The default database is the one where on the primary I set the login to have the correct database mappings, and the correct default database. When the failover happens, the default database is correct, but the user is not mapped to the database. At all. I know these mappings are at the database level which is why this is throwing me for a loop.

Best Answer

If the login is a Windows login, and is present on both the Primary and Secondary servers, you should only need to add the database user to the Primary Replica.

This is because database users are at the database level and the creation of the user itself will be replicated to the secondary replica. As this is a Windows login, it then follows that the SID will already match.