Follow

Steps for creating users in SQL AlwaysOn

NOTE: This does not apply to Windows logins, only SQL logins.

  1. Connect to the AlwaysOn listener. This ensures you are working with the primary node.
  2. Create the SQL Login and database mappings, security settings, etc.
  3. Next, run this query:
    SELECT SUSER_SID ('USERNAME')

    This will return the user's SID which is the unique identifier for the login. Even if the names match, unless the SID is the same the SQL login will not work properly on the secondary node after a failover.
  4. Connect to the secondary node. Be sure to check/refresh the Availability Group to ensure you are working with the correct node.
  5. Copy the SID into the following query, also update the username and default database as needed. Be sure to use the same password as you did when first creating the user.

    USE [master]
    GO
    CREATE LOGIN [USERNAME] WITH PASSWORD=N'PASSWORD', SID=[SID from prior query], DEFAULT_DATABASE=[Master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
    GO

    This should create the SQL login on the secondary node with the same username, password, SID and default database.
  6. If you wish to test, open the Availability Group dashboard, ensure it is "all green" and then initiate a manual failover. This will make the secondary the primary and vice versa.
  7. Test your new login.
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments