0

Hello all,
I want to create a stored procedure using SMO Objects. I have set up all the properties of my Smo.StoredProcedure object, but when i try to create it, it throws me this Exception Message: Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch Here's a little snippet of my code:

protected void btnCreateNewSP_Click(object sender, EventArgs e)
    {
        StoredProcedure sp = (StoredProcedure)Session["SP"];
        sp.TextBody = txtSqlStatement.Text;
        

        try
        {
            sp.Create();
            lblErrorInfo.ForeColor = System.Drawing.Color.Green;
            lblErrorInfo.Text = "Stored Procedure has been successfuly created!";
        }
        catch (Exception ex)
        {
            lblErrorInfo.ForeColor = System.Drawing.Color.Red;
            lblErrorInfo.Text = ex.Message + " Error Info: " + ex.InnerException.Message;
        }
    }
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ramesh S
1

Hi Alexpap ,

Post the complete error message. Becuase the error message that you posted is generic for SMO object.

Also Check the following things:

1. Database connection is estabilished before executing 'Create' method for StoredProcedure object by putting a break point.
2. sp.TextBody has correct syntax.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.