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;
        }
    }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.