Solved

Linked server stored procedure

Posted on 2013-06-11
5
520 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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