• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

Linked server stored procedure

Hi

I have to call stored procedure on remote server using Linked server(SQL). stored procedure expects 10 parameters to be passed.  It also raise exception if something goes wrong. Would it be good practice to call linked server stored procedure directly from C# code or i should have stored procedure on local server sql that in turn calls linked server stored procedure. Can somebody suggest how to do it? i.e syntax and snippet

Thanks
0
KashyapVachhani
Asked:
KashyapVachhani
1 Solution
 
CodeCruiserCommented:
>I have to call stored procedure on remote server using Linked server(SQL)

>call linked server stored procedure directly from C#

Linked server is a SQL Server concept so if you call it directly from C# then its not linked server. Do you have access to this server directly from C#? I think you can do it either way.
0
 
vivekkumarSharmaCommented:
You can call it in either way.

But
I think you should have stored procedure on local SQL server that in turn calls linked server stored procedure.
If you call multiple servers from your program, It will leads to confusion and will create extra efforts to maintain multiple connection string.
0
 
Christopher GordonSenior Developer AnalystCommented:
If I understand your question,

If you have appropriate permissions, I would create an additional connectionstring in the web.config file to call the stored procedure to the additional SQL Server box directly.  Just wrap that call in a standard Try Catch block in your C# code.
0
 
lluddenCommented:
If possible, call the server directly.  A linked server just adds unnecessary complexity.
0
 
BAKADYCommented:
This works for me,... let me now if you have problem running this:
EXEC yourDatabaseAtLinkedServer.dbo.yourStoredProcedure 'parametersIfRequired', 1, 2, 3, ...
AT YourLinkedServer
GO

Open in new window

http://msdn.microsoft.com/de-de/library/ms188332.aspx
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now