Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


run a stored procedure in sybase datbase using a C# program

Posted on 2006-06-08
Medium Priority
Last Modified: 2012-05-05
Please advice on how I can do that?  Thanks,  Lalit
Question by:khyberman
  • 2

Accepted Solution

lostcarpark earned 2000 total points
ID: 16866554
First you need the Sybase OLEDB adapter, which you should find on the Sybase ASE CD (or similar). Make sure you grant the ASP_NET user read and execute permission on the directory you install it in.

Next you need to run the OLEDB configuration utility to create a connection to your database.

You then need to set up a connection string for the OleDbConnection object. The easist way to create one is to use create a database connection under the Servers tab in VS and copy the resulting connection string.

The code to run your stored procedure goes along the lines of:

Dim dbConn As New OleDbConnection(connectionString)
Dim sql As String = "Execute MyStoredProcedure " & myParamVal
Dim dbCmd As New OleDbCommand(sql, dbConn)

Or if your procedure contains a select statement and returns a resultset, replace the last line with:

Dim dbReader as OleDbReader = dbCmd.ExecuteReader()

I don't have source code here, so that might not be quite right. I can look it up in the morning. Note that you can pass paramaters using the parameter collection, but most of the time I find it easier to just concatinate them into the query. Be very careful how you handle user input, however. Parse it careful to guard against SQL injection attacks.

Expert Comment

ID: 16866562
Meant to say, sorry my examples are in VB.NET. It should be easy enough to adapt them to C#.

ALl the best,


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

564 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