Solved

Linked server stored procedure

Posted on 2013-06-11
5
504 Views
Last Modified: 2013-06-20
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
Comment
Question by:KashyapVachhani
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39240320
>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
 
LVL 2

Expert Comment

by:vivekkumarSharma
ID: 39240474
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
 
LVL 14

Expert Comment

by:Christopher Gordon
ID: 39240818
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
 
LVL 18

Expert Comment

by:lludden
ID: 39241202
If possible, call the server directly.  A linked server just adds unnecessary complexity.
0
 
LVL 4

Expert Comment

by:BAKADY
ID: 39242805
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now