473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Linking Two SQL Servers

Two SQL Servers
1) "Test"
Payroll DB
Transaction Table
pr_SubmitTransaction in Payroll DB
********************************************
2) "Production"
Payroll DB
Transaction Table
Pr_SubmitTransaction in Payroll DB
Accounts DB
Pr_VerifyAccounts (@AcctNumber)
********************************************

I want to use same pr_VeriftAccounts in both test and production
Pr_SubmitTransaction stored procedure.
The pr_SubmitTransaction in production works fine when I say
Exec Payroll.dbo.pr_VerifyAccounts as it is on same server. (WORKS
FINE)
Exec [PRODUCTION].Payroll.dbo.pr_VerifyAccounts (DOES NOT WORK)

Should I use sp_addlinkedServer ?? to do this ?. Please provide me some
feedback.
I know I can acheive this by front end, but I was do it in one stored
procedure.

Jul 23 '05 #1
7 8373
(m.******@gmail.com) writes:
Two SQL Servers
1) "Test"
Payroll DB
Transaction Table
pr_SubmitTransaction in Payroll DB
********************************************
2) "Production"
Payroll DB
Transaction Table
Pr_SubmitTransaction in Payroll DB
Accounts DB
Pr_VerifyAccounts (@AcctNumber)
********************************************

I want to use same pr_VeriftAccounts in both test and production
Pr_SubmitTransaction stored procedure.
The pr_SubmitTransaction in production works fine when I say
Exec Payroll.dbo.pr_VerifyAccounts as it is on same server. (WORKS
FINE)
Exec [PRODUCTION].Payroll.dbo.pr_VerifyAccounts (DOES NOT WORK)

Should I use sp_addlinkedServer ?? to do this ?. Please provide me some
feedback.
I know I can acheive this by front end, but I was do it in one stored
procedure.


Yes, you would use sp_addlinkedserver. Of Production is called
that, and is an SQL Server as well, it's as easy as:

sp_addlinkedserver PRODUCTION

Hm, well, OK, maybe authentication does not work out of the box. In
this case you need to use sp_addlinkedsrvlogin.

Both these procedures are well described in Books Online.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Thanks for taking your time and effort replying to my question.Looks
like its working, I can see the results in query analyzer but with one
error
Server: Msg 15028, Level 16, State 1, Procedure sp_addlinkedserver,
The server 'PRODUCTION' already exists. (How can I get rid of this????)

Is it because PRODUCTION is already registered in my enterprise manager
or is it because PRODUCTION is not removed (sp_droplinkedserver or
something like that) in stored procedure?

When I run the stored procedure from front end I am getting an Error
"Server: Msg 15028, Level 16, State 1, Procedure sp_addlinkedserver" on
mycmd.ExecuteNonQuery, It is executing the stored procedure perfectly
(all my insert statements in stored procedures are executed).

Jul 23 '05 #3
(m.******@gmail.com) writes:
Thanks for taking your time and effort replying to my question.Looks
like its working, I can see the results in query analyzer but with one
error
Server: Msg 15028, Level 16, State 1, Procedure sp_addlinkedserver,
The server 'PRODUCTION' already exists. (How can I get rid of this????)

Is it because PRODUCTION is already registered in my enterprise manager
or is it because PRODUCTION is not removed (sp_droplinkedserver or
something like that) in stored procedure?


Depends on what you mean with "registered in Enterprise Manager". If
you mean a server listed directly under a server group in the tree,
no this has nothing to do with linked servers. The registered servers
are stored in the local registry, out of reach for SQL Server itself.

On other hand if you mean that you had previously registered PRODUCTION
as a linked server from Enterprise Manager, your understanding is right.
In fact, all the management GUI:s in Enterprise Manager are basically
only wrappers on SQL commands and system procedures. So, in fact if
you want to do what EM does, but from code, you can use the Profiler
to eavesdrop on what Enterprise Manager emits.

I don't remember for sure, but I believe that the command to drop a
linked server is sp_dropserver. The topic for sp_addlinkedserver in
Books Online should have a See Also to that topic.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
As you suggested I had to use exec sp_dropserver
'PRODUCTION','droplogins'
Thanks a lot. Everything works great.

Jul 23 '05 #5
still issues......
In stored procedure itself I have two statements which says
Exec sp_addlinkedServer 'PRODUCTION'
Exec sp_addlinkedsrvlogin 'PRODUCTION','false',NULL,@LoginName,@Pwd
Insert into [PRODUCTION]. --bla -bla
Insert into <Localtable> --bla bla
And in the end I have sp_removeserver [PRODUCTION]

When I compile, it throws an error saying PRODUCTION is not in
sysservers. But If I issue sp_addlinkedserver from outside, then it
will let me compile.
If you check I am doing that inside the code, so when ever it requires
it, it is there.
Presently I have to call three procedures from front end, One to
Linkserver, one to do my regular insertion and all, and finally to drop
server as a work around.
Can this be put in one stored procedure ??

Thanks again

Jul 23 '05 #6
(m.******@gmail.com) writes:
still issues......
In stored procedure itself I have two statements which says
Exec sp_addlinkedServer 'PRODUCTION'
Exec sp_addlinkedsrvlogin 'PRODUCTION','false',NULL,@LoginName,@Pwd
Insert into [PRODUCTION]. --bla -bla
Insert into <Localtable> --bla bla
And in the end I have sp_removeserver [PRODUCTION]

When I compile, it throws an error saying PRODUCTION is not in
sysservers. But If I issue sp_addlinkedserver from outside, then it
will let me compile.
If you check I am doing that inside the code, so when ever it requires
it, it is there.
Presently I have to call three procedures from front end, One to
Linkserver, one to do my regular insertion and all, and finally to drop
server as a work around.
Can this be put in one stored procedure ??


You could have a procedure that first sets up the linked server, and
then calls the inner procedure.

As for the linked server having to be set up when you create the procedure,
there is not much to do about it.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
I think I can live with it. I got two procedures now one to add/remove
linked server and one for business logic. Thanks for all your help

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: George Hernandez | last post by:
I have a site on a set of Linux Servers where my site is PHP enabled and I would like to prevent people from externally linking to content on my site and replace it with a warning image. I've...
1
by: Steve Thorpe | last post by:
Hi. I have two sql servers and have ran exec sp_addlinkedserver 'ACSPSM', N'SQL Server' to link one to the other and also vise versa. Each server has two users permissioned. My problem is...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
0
by: gasturbtec | last post by:
please help im new at access programming and i just got this project dropped in my lap because the old programmer quit. i've been doing ok so far but now i need to add code to an existing database...
18
by: Mark P | last post by:
I have a bit of vb code that uses Tables.Append to programatically link tables from Oracle and DB2 datasources. The problem I am having on some client machines is that the link will take anywhere...
17
by: Nitro | last post by:
I'm having problems getting my DB to Link to different SQL servers. I got it to work fine on my own machine, but when distributed it at the client, and to another office, the Link didn't work. It...
3
by: misscrf | last post by:
In a database, I am creating a new db. From there, I am setting up the tables, so that I can eventually create a front end (usually access, but I may attempt to be brave and lose the shell.) ...
0
by: vikram1102 | last post by:
can i link other database servers with db2 on local machine as well as remote machines...? help me...
2
by: =?utf-8?B?UMSBdmVscyBNaWhhaWxvdnM=?= | last post by:
Hello, I have a problem. I've linked MySql server to MsSql, in MySql I have a table with Latvian data(character set is ucs2, ucs2_general_ci) and the problem is that when I use openquery to read...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.