Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sp_addlinkedserver syntax

Tags:

sql-server

I would like to make a copy of what's on my remote server at xxx.safesecureweb.com. How do I connect to it from my local SQL Server?

Is the syntax something like:

sp_addlinkedserver 
@server='PRODUCTION', 
@provider='xxx.safesecureweb.com',
@Username='myUsername', 
@Password='myPassword'

What I'm thinking of doing is writing a bunch of insert statements like:

INSERT INTO Test.Table
SELECT * FROM Production.Table
like image 316
Phillip Senn Avatar asked Jun 30 '10 16:06

Phillip Senn


People also ask

What is Sp_addlinkedserver?

A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources. After a linked server is created by using sp_addlinkedserver , distributed queries can be run against this server. If the linked server is defined as an instance of SQL Server, remote stored procedures can be executed.

How do I get a list of linked servers in SQL Server?

The easiest method to view the details for one or all linked servers is the query the SQL Server system tables. Rather than viewing limited information or having to manually view the set-up code for each linked server, a query to the system tables will show amazing detail of all linked servers in one go.

How do I remove a linked server in SQL?

To remove all remote and linked server logins for a server when you remove the server, use the droplogins argument. sp_dropserver cannot be executed inside a user-defined transaction.


1 Answers

You do not specify the remote user and password in the linked server definition. Linked servers have a separate object that mapps the login of users connected to the local server (the 'locallogin') with remote logins. See Security for Linked Servers. For example, the following maps all local logins on the linked server to the specified MyUserName SQL Login:

exec sp_addlinkedserver 'xxx.safesecureweb.com';
exec sp_addlinkedsrvlogin 'xxx.safesecureweb.com'
    , 'FALSE', NULL, 'myUserName', 'myPassword';

You can only map with user/password a remote SQL login. Remote Windows logins (trusted authentication) must use integrated authentication and configure the server for constrained delegation.

like image 76
Remus Rusanu Avatar answered Oct 20 '22 12:10

Remus Rusanu