Skip to content
Advertisement

SQL Server – Add a linked server to AWS RDS instance

From this AWS link it explains how to add a linked server: https://aws.amazon.com/blogs/database/implement-linked-servers-with-amazon-rds-for-microsoft-sql-server/

Specifically these commands

EXEC master.dbo.sp_addlinkedserver @server = N’REPLTest2′, @srvproduct=N”, @provider=N’SQLNCLI’, @datasrc=N’repltest2.datacenter.mycompany.com′;
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N’REPLTest2′,@useself=N’False‘,@locallogin=NULL,@rmtuser=N'<username>’,@rmtpassword=‘<password>’;

The main problem is it seems to be a mix of ‘, `, and “

I get syntax errors, and I assume that’s why. Plus, I don’t know why it has the N before a bunch of them. It looks to me like they copy and pasted the commands, but the characters changed. I’m not sure how to fix these syntax errors.

I ran it as is without changing anything. I knew it would error because the connection variables weren’t changed, but I wanted to see the syntax errors:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘’’.

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ‘’’.

Msg 105, Level 15, State 1, Line 2
Unclosed quotation mark after the character string ‘’,@rmtpassword=‘’; ‘.

Advertisement

Answer

I got it working, but want to leave the question in case others run into the same problem. Below is the corrected syntax.

EXEC master.dbo.sp_addlinkedserver @server = 'REPLTest', @srvproduct='', @provider='SQLNCLI', @datasrc='IP-or-url';
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname='REPLTest',@useself='False',@locallogin=NULL,@rmtuser='username',@rmtpassword='password';
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement