SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Executing stored procedures on Linked Servers


Executing stored procedures on Linked Servers

Author
Message
Grinja
Grinja
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1801 Visits: 630
Hi,
I currently have two DB's (DB1 and DB2) setup on an instance of SQL server. DB2 is essentially a reporting store which I populate with data from DB1

Currently: my Extract script takes the following parameters:
@sourceDatabase sysname, @YearMonthStart int, @YearMonthEnd int


Within the script I list a number of tables to be populated based on these parameters.
INSERT INTO TableX
EXEC ('USE '+ @sourceDatabase + ' EXEC spPopulateTableX')



I am now migrating DB2 to new server and the two servers are setup as linked servers.
So I cannot use 'USE' anmore.

So essentially my questions is how do a reference the source database in my script?

All help is appreciated.
G
The Dixie Flatline
The Dixie Flatline
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28708 Visits: 6931
Try this: EXEC database.schema.procedureName

If your database is called Reports, and your procedure is dbo.InventorySummary you would use:

EXEC Reports.dbo.InventorySummary.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Grinja
Grinja
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1801 Visits: 630
Thanks Bob that works for me.

A bit off topic...in order to execute the storedProcs on the DB1 the linked server needs to be configured to allow remote procedure calls.
Is this a good practice security wise?
Should I perhaps look at ways to get the data without executing the storeprocs on the DB1.
The Dixie Flatline
The Dixie Flatline
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28708 Visits: 6931
It creates yet another vulnerability, if you don't maintain control over who is allowed to execute which stored procedures. Someone more DBA focused could give you a better answer than I can.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Grinja
Grinja
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1801 Visits: 630
Thanks again.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search