RaiseError

Discussion in 'ASP .Net' started by shapper, Sep 14, 2007.

  1. shapper

    shapper Guest

    Hello,

    I am raising an error on my SQL 2005 procedure as follows:

    RAISERROR(@ErrorMessage, @ErrorSeverity, 1)

    How can I access it in my ASP.NET code? I am using Enterprise Library
    Data Block to access the database.

    This is the code I have:

    Try
    Dim dbBlog As Database = DatabaseFactory.CreateDatabase("MyDB")
    Dim dbcBlog As DbCommand =
    dbBlog.GetStoredProcCommand("by27_Blogger_CreateBlog")
    dbBlog.AddInParameter(dbcBlog, "@BlogName", DbType.String, name)
    dbBlog.AddInParameter(dbcBlog, "@BlogComment", DbType.String,
    comment)
    dbBlog.ExecuteNonQuery(dbcBlog)
    Catch ex As System.Exception
    End Try

    Thanks,

    Miguel
     
    shapper, Sep 14, 2007
    #1
    1. Advertising

  2. shapper

    OZI Guest

    Did you put a break point at your Catch statement?
    If not caching the error then maybe the DataBock might be eating it or
    something.
    is Severity Level 1 enough? why not increase it to 16 or beyond.

    OZI


    "shapper" <> wrote in message
    news:...
    > Hello,
    >
    > I am raising an error on my SQL 2005 procedure as follows:
    >
    > RAISERROR(@ErrorMessage, @ErrorSeverity, 1)
    >
    > How can I access it in my ASP.NET code? I am using Enterprise Library
    > Data Block to access the database.
    >
    > This is the code I have:
    >
    > Try
    > Dim dbBlog As Database = DatabaseFactory.CreateDatabase("MyDB")
    > Dim dbcBlog As DbCommand =
    > dbBlog.GetStoredProcCommand("by27_Blogger_CreateBlog")
    > dbBlog.AddInParameter(dbcBlog, "@BlogName", DbType.String, name)
    > dbBlog.AddInParameter(dbcBlog, "@BlogComment", DbType.String,
    > comment)
    > dbBlog.ExecuteNonQuery(dbcBlog)
    > Catch ex As System.Exception
    > End Try
    >
    > Thanks,
    >
    > Miguel
    >
     
    OZI, Sep 14, 2007
    #2
    1. Advertising

  3. shapper

    Darren Kopp Guest

    On Sep 14, 1:02 pm, shapper <> wrote:
    > Hello,
    >
    > I am raising an error on my SQL 2005 procedure as follows:
    >
    > RAISERROR(@ErrorMessage, @ErrorSeverity, 1)
    >
    > How can I access it in my ASP.NET code? I am using Enterprise Library
    > Data Block to access the database.
    >
    > This is the code I have:
    >
    > Try
    > Dim dbBlog As Database = DatabaseFactory.CreateDatabase("MyDB")
    > Dim dbcBlog As DbCommand =
    > dbBlog.GetStoredProcCommand("by27_Blogger_CreateBlog")
    > dbBlog.AddInParameter(dbcBlog, "@BlogName", DbType.String, name)
    > dbBlog.AddInParameter(dbcBlog, "@BlogComment", DbType.String,
    > comment)
    > dbBlog.ExecuteNonQuery(dbcBlog)
    > Catch ex As System.Exception
    > End Try
    >
    > Thanks,
    >
    > Miguel


    Catch SqlException. You can find out what the raiseerror was with the
    Errors collection. You can use this as a reference

    SqlException MSDN - http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.errors.aspx
    SqlError MSDN - http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlerror.aspx
     
    Darren Kopp, Sep 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page