Linked Servers in SQL Server 2005

by Allan Svelmøe Hansen July 16, 2008 08:08
So I was faced with a problem the other day where I had to map data from one datasource to another (well, common problem) but both of the sources were SQL Servers, and I had to map the data based on some system ids and names, so I couldn’t just move all the data between the sources.
I then looked up the linked servers and was surprised at how easy that was.

Basically – all I needed to do what set up a linked server by using the following system stored procedures:
sp_addlinkedserver '<Server Alias>''''SQLNCLI', NULL, NULL, 'SERVER=<IP>', NULL 
sp_addlinkedsrvlogin '<Server Alias>''false', NULL, '<username>''<password>' 


The first call sets up the server, whereas the second one sets up a log in to the server.

Be aware that the traffic between the servers as far as I know are sent pretty plain text/not encrypted, so I would not advice this to run for a prolonged time in a product environment lest it is located behind some VPN or similar.

To remove the linked server once done then just call

sp_dropserver '<Server Alias>''droplogins'
 

Linking servers means you can access a different database server with a qualified name, as if it was on the same database server.

If I for instance set up a linked server called myRemoteServer, then I would be able to access a table in the remote database using:
myRemoteServer.<DatabaseName>.<SchemaName>.<TableName>

It makes it relative much easier to map data between sources compared to having to backup/restore the remote source database to the target server.
Bookmark and Share DotnetKicks dotnetshoutout

Comments

8/29/2008 3:48:15 PM #

I have linked 2005 machines together.  I have a SQL2000 machine in our environment.  I cannot get a SQL2005 server to link it.

Sam Schlagel United States

8/29/2008 6:51:52 PM #

I have personally not had any problems linking to a 2000 server from a 2005, by using the above method.
Are you sure there is access between the machines?

Allan S. Hansen

7/28/2009 3:21:22 PM #

I can't use the user defined function , how to obtain that

Ali Egypt

8/12/2009 2:58:29 PM #

Can you link a SQL express server and SQL? I tried with no luck.

Baby United States

5/23/2010 3:00:19 PM #

Pingback from detailedtutorials.com

Linked Servers in SQL Server 2005

detailedtutorials.com

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen | Modified by Mooglegiant

About:
Allan Svelmøe Hansen

My real name is Allan Svelmøe Hansen.
I live in Denmark, where I work as a developer for hedal:kruse:brohus using SQL Server and the .NET framework since 2004.
My primary fields of expertise is back-end data integration, database design and optimization.


       View Allan Svelmøe Hansen's profile on LinkedIn     

Disclaimer

The opinions expressed herein are my own personal opinions and thoughts and does not represent my employers view in any way, nor are my results guaranteed for all situations.
Content is presented "as is", with no warranty.