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

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

    Accepted Solution

    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.
    LVL 5

    Expert Comment

    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

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    21 Experts available now in Live!

    Get 1:1 Help Now