Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making SQL Server a Linked Server [closed]

I have a production database off site on another box which I reference by IP. Lets say its IP:

123.45.67.89

Now I want to do a query that references both my server here locally called MYSERVER1 with my production server.

When I try to do:

select count(*) from [MYSERVER1].MyDBName.dbo.mytable;

everything is fine. But I can't do this:

select count(*) from [123.45.67.89].MyDBName.dbo.mytable;

Is there a way to link the servers? Like using sp_addLinkedServer?

I get this error:

Msg 7202, Level 11, State 2, Line 3
Could not find server '123.45.67.89' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.

Any ideas? (I want to copy X number of rows to my production server, that's why)

like image 806
cdub Avatar asked Jun 21 '26 07:06

cdub


1 Answers

In SQL Management Studio add your remote server: first connect to your local server, go to Server Objects\Linked Server in the Object Explorer and right click and add a new one.

BTW: you can also do it with system storedprocs, but it is something that you do only occasionally I would stay with the GUI.

like image 195
rufo Avatar answered Jun 23 '26 01:06

rufo