Map multiple local SQL logins to just one remote login for Linked Server

techresearch7777777 1,981 Reputation points
2020-11-12T23:41:11.227+00:00

Hello, will my following scripts work?

I'm aiming to have 2 different (or more if needed) local logins map to just 1 remote login.

-- CREATE a Linked Server.

EXEC sp_addlinkedserver
@Testta =N'Remote_SQL_Sever_Linked_Server',
@srvproduct=N'',
@provider=N'SQLNCLI',
@datasrc=N'Remote_SQL_Sever_Linked_Server';

-- DROP all local Logins for this Linked Server.

EXEC sp_droplinkedsrvlogin 'Remote_SQL_Sever_Linked_Server', NULL

-- Add one local Login for this Linked Server.

EXEC sp_addlinkedsrvlogin
@rmtsrvname=N'Remote_SQL_Sever_Linked_Server',
@useself=N'FALSE',
@locallogin='Login_Name_1',
@rmtuser=N'Login_Name_1',
@rmtpassword=N'SomeStrongPassword'

-- Add another different local Login for this Linked Server using same remote login.

EXEC sp_addlinkedsrvlogin
@rmtsrvname=N'Remote_SQL_Sever_Linked_Server',
@useself=N'FALSE',
@locallogin='Login_Name_2',
@rmtuser=N'Login_Name_1',
@rmtpassword=N'SomeStrongPassword'

Thanks in advance.

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2020-11-13T07:14:28.9+00:00

    Hi @techresearch7777777 ,

    >will my following scripts work?

    Yes, it will work. I checked this in my environment.

    39632-screenshot-2020-11-13-150704.jpg

    39569-screenshot-2020-11-13-150741.jpg

    39662-screenshot-2020-11-13-150806.jpg

    39671-screenshot-2020-11-13-150911.jpg

    Best regards,
    Cathy Ji


    If the response is helpful, please click "Accept Answer" and upvote it.
    Hot issues October--Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. techresearch7777777 1,981 Reputation points
    2020-11-13T16:06:04.377+00:00

    Thanks for your quick and excellent detailed proof reply Cathy, much appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.