Monday, November 14, 2016

Create SQL Login in SQL AlwaysOn availability group servers

How to create SQL login in SQL AlwaysOn Availability group databases

First create SQL Login in Primary replica
Example : Login : TESTLOGIN, Password : test, Database : DBA, db_datareader

Find SID of SQL Login in Primary replica

Run the following query in primary SELECT SUSER_SID ('TESTLOGIN') to find SID of the SQL login in Primary replica
Copy the query result which is SID, Example : 0x4063F34B8AF7A041B66CF243AAC79ECC

Create the same SQL Login in Secondary node using the script below. Paste the SID from primary node in SID area, password in passsword.
In the script below, update the areas LOGIN, PASSWORD, SID, DEFAULT_DATABASE

USE [master]
GO

CREATE LOGIN [TESTLOGIN] WITH PASSWORD=N'test
,SID=0x4063F34B8AF7A041B66CF243AAC79ECC, DEFAULT_DATABASE=DBA,
DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

After updating the query, Run the query in Secondary node

We use the same SID for SQL login in order to work after failover happens.

Thank you for reading.

No comments:

Post a Comment

How to add a Database to AlwaysOn Availability Group with four different options

To add a database to an existing AlwaysOn availability group, MS has given us four options to choose from Automatic seeding Full database an...