To add server using sp_addlinkedserver

Sql ServerTsql

Sql Server Problem Overview


I tried to insert values from one server to another server and I got the error:

> Msg 7202, Level 11, State 2, Line 1 Could not find server > 'SNRJDI\SLAMANAGEMENT' in sysservers. Execute sp_addlinkedserver to > add the server to sysservers.

Sql Server Solutions


Solution 1 - Sql Server

I got it. It worked fine

Thank you for your help:

EXEC sp_addlinkedserver @server='Servername'

EXEC sp_addlinkedsrvlogin 'Servername', 'false', NULL, 'username', 'password@123'

Solution 2 - Sql Server

Add the linked server first with

exec sp_addlinkedserver
@server = 'SNRJDI\SLAMANAGEMENT',
@srvproduct=N'',
@provider=N'SQLNCLI'

See http://msdn.microsoft.com/en-us/library/ms190479.aspx

Solution 3 - Sql Server

I had the same issue connecting an SQL_server 2008 to an SQL_server 2016 hosted in a remote server. @Domnic 's answer didn't worked for me straightforward. I write my tweaked solution here as I think it may be useful for someone else.

An extended answer for remote IP db connections:

Step 1: Link servers

EXEC sp_addlinkedserver @server='SRV_NAME',
   @srvproduct=N'',
   @provider=N'SQLNCLI',   
   @datasrc=N'aaa.bbb.ccc.ddd';
   
EXEC sp_addlinkedsrvlogin 'SRV_NAME', 'false', NULL, 'your_remote_db_login_user', 'your_remote_db_login_password'

...where SRV_NAME is an invented name. We will use it to refer to the remote server from our queries. aaa.bbb.ccc.ddd is the ip address of the remote server hosting your SQLserver DB.

Step 2: Run your queries For instance:

SELECT * FROM [SRV_NAME].your_remote_db_name.dbo.your_table

...and that's it!

Syntax details: sp_addlinkedserver and sp_addlinkedsrvlogin

Solution 4 - Sql Server

FOR SQL SERVER

EXEC sp_addlinkedserver @server='servername' 

No need to specify other parameters. You can go through this article.

Solution 5 - Sql Server

-- check if server exists in table sys.server

select * from sys.servers

-- set database security

	EXEC sp_configure 'show advanced options', 1
	RECONFIGURE
	GO

	EXEC sp_configure 'ad hoc distributed queries', 1
	RECONFIGURE
	GO

-- add the external dbserver

EXEC sp_addlinkedserver @server='#servername#'

-- add login on external server

EXEC sp_addlinkedsrvlogin '#Servername#', 'false', NULL, '#username#', '#password@123"'

-- control query on remote table

select top (1000) * from [#server#].[#database#].[#schema#].[#table#]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDomnicView Question on Stackoverflow
Solution 1 - Sql ServerDomnicView Answer on Stackoverflow
Solution 2 - Sql ServerhkfView Answer on Stackoverflow
Solution 3 - Sql ServerMarcMView Answer on Stackoverflow
Solution 4 - Sql ServerRohan BhutaniView Answer on Stackoverflow
Solution 5 - Sql ServerwikeView Answer on Stackoverflow