The
purpose of this article is to provide a step-by-step method of creating a linked
server that point to a server different from its name. Configuring a linked
server in this manner is very handy when we need to execute SQL scripts
containing linked server names in our different environments.
Once completed the configuration of linked server for server ‘A’. It should be
points to itself (Server ‘A’) only.
But instead of pointing the same server (server ‘A’), you can also point it to some other server (server ‘B’). If
you point the Linked server ‘A’ to server B‘, then Linked server ‘A’ will extract all the data from
server ‘B’.
technique is very useful while working in different environments (dev, test, pre-production)
with scripts having linked server names added at different places.
assume that our scripts have linked server name referring to a production
server mentioned at many different places. We may not be able to test the
script with respect to the production server. Also every time changing the code
(e.g.renaming the linked server for testing) is not good. In this scenario, we
can use our technique to create a linked server (may be our production server) that
points to our development server but with a name same as the production server.
Thus, we will be able to use the same script in different environments without
changing the linked server names.
Server is a mechanism in SQL Server by which we can add other SQL Server to a
Group on a different SQL Server instance and query both the SQL Server DBs
using T-SQL Statements. A linked server definition specifies an OLE DB provider
and an OLE DB data source. With a linked server, you can create very clean,
easy to follow, SQL statements that allow remote data to be retrieved, joined
and combined with local data.
Approach 1 – Using Script to create Linked Server
LinkedServer ******/
–Provide a Name for Linked server by which we want to create it
@server = N’BIMSQL01‘,
@srvproduct=N’SQL Native Client’,
@provider=N’SQLNCLI’,
/*Name of the server that we want to point. Please note that the name of the linked server and the actual server it points to are different.*/
@datasrc=N’BIMSQL02‘,
Persist Security Info=False;
Initial Catalog=ITSDB;
Data Source=BIMSQL02′
NULL.
Approach 2 – Using Linked Server Wizard
the steps below for configuring the linked server that points to a server
different from its name:
creating the linked server, go to Start, All Programs, Microsoft SQL Server 2008, SQL Server Management studio.
It will open connection window. Check the server name & connect it.
Management studio, go to Server Objects, Linked Servers.
Right click on the Linked server
folder and click on New Linked Server…
will open the Linked server configuration window.
configuring the linked server, fill the following required information about the linked server:
server: Provide the name with which you are going to refer the linked server.
For Ex: BIMSQL01
Type: Other data source
SQL Native Client
SQL Native Client
Source: The data source is usually the name of the database server. So, here
you need to give the name of the actual server (BIMSQL02) on which you want to query data remotely. Please note
that the name of the linked server and the actual server it points to are
different.
string: Here you need to provide the
complete connection string for the server (BIMSQL02).
The format of connection string is shown below:
Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=ITSDB;
Data Source=BIMSQL02
It is optional field. You can mention
the database name here.
to Security tab
with the linked server. For this document, we are using windows authentication.
For windows authentication, you can choose connection will “Be made using the logins current security
context”.
login and password.
giving the complete information, click Ok.
It will create the Linked server named ‘BIMSQL01’
that will actually extract the data from BIMSQL02 server.
checking the Linked server, go to Server objects,
Linked server, Expand the linked server folder. It enlists the entire linked servers. Verify
that ‘BIMSQL01’ should be in the
list.
testing the linked server connection, right click on the linked server (BIMSQL01) and click Test Connection.
the data retrieval using T-SQL:
FROM BIMSQL01.ITSDB.dbo.Region
server instead of BIMSQL01 server.
of Document—————————————-