Catching update exception in DetailsView/GridView (difference?)

Posts   
 
    
AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 06-Feb-2007 14:06:02   

Hi there!

I have two pages, one with a gridview and one with a detailsview.

When an update exception occurs in the detailsview, my ItemUpdated event still fires and I can handle the exception there.

In the gridview, I would expect to be able to do the same using RowUpdated event, but my event does not fire; it goes directly to my error page for 'unhandled exceptions'.

I know this is more of a general Asp.Net question, but are you aware that there should be a difference? The articles I found about this way to handle exceptions does not indicate a difference (and the e.Exception property does not make much sense if an exception prevents event from firing).

As always - any help appreciated,

Anders, Denmark

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 06-Feb-2007 17:25:59   

Hello,

if you are in debug mode, you can see where your exception is throw where an error occured in your gridview? So you can add an handler to this error using the call stack to see where the exception is throw? What is the cause of the exception? An llblgen call or a third method call?

AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 06-Feb-2007 18:50:21   

DetailsView (Caught by ItemUpdated)

System.ArgumentOutOfRangeException was unhandled by user code Message="The value specified will cause an overflow error in the database. Value length: 529. Column max. length: 500 Parameter name: VendorName" ParamName="VendorName" Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object value, Int32 fieldIndex) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(Int32 fieldIndex, Object value, Boolean fireChangeEvent) at GE.EntityClasses.SupplierEntity.SetNewFieldValue(Int32 fieldIndex, Object value) in C:\Documents and Settings\anjni\My Documents\Visual Studio 2005\Projects\GlobalEye_LLBL\DatabaseGeneric\EntityClasses\SupplierEntity.vb:line 162 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(String fieldName, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.SetEntityValues(IDictionary values, IEntity2 entity) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback)

GridView: (Sends me to the error page)

System.ArgumentOutOfRangeException was unhandled by user code Message="The value specified will cause an overflow error in the database. Value length: 518. Column max. length: 500 Parameter name: Name" ParamName="Name" Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object value, Int32 fieldIndex) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(Int32 fieldIndex, Object value, Boolean fireChangeEvent) at GE.EntityClasses.ScorecardEntity.SetNewFieldValue(Int32 fieldIndex, Object value) in C:\Documents and Settings\anjni\My Documents\Visual Studio 2005\Projects\GlobalEye_LLBL\DatabaseGeneric\EntityClasses\ScorecardEntity.vb:line 134 at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(String fieldName, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.SetEntityValues(IDictionary values, IEntity2 entity) at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback)

AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 06-Feb-2007 18:53:51   

DetailsView, ItemUpdated (Catches exception)


    Protected Sub dvSupplier_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles dvSupplier.ItemUpdated
        If (e.Exception Is Nothing) Then

            Dim adap As GE.DatabaseSpecific.DataAccessAdapter = New GE.DatabaseSpecific.DataAccessAdapter(GEConfig.ConnectionString)

            updateQualificationLevelRelations(adap)

            saveApprovalLevelChangeLogMessage(adap)
            saveClassificationLevelChangeLogMessage(adap)

            saveGeneralChangeLogMessage(adap)

            Dim refUrl As String = "SupplierOverview.aspx?supplierid=" & suppId
            'sendMailToSupplierOwners(refUrl)

            ' In case of submit, we transfer to the page we came from
            Response.Redirect(refUrl)
        Else
            lblErrorWhenUpdating.Visible = True
            lblErrorWhenUpdating.Text = e.Exception.Message()
            e.KeepInEditMode = True
            e.ExceptionHandled = True
        End If
    End Sub

GridView, RowUpdated (Doesn't catch exception)


    Protected Sub gvScorecardSection_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvScorecardSection.RowUpdated
        If (e.Exception IsNot Nothing) Then
            lblErrorWhenUpdating.Visible = True
            lblErrorWhenUpdating.Text = e.Exception.Message()
            e.KeepInEditMode = True
            e.ExceptionHandled = True
        End If
    End Sub

AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 06-Feb-2007 18:58:25   

jbb wrote:

Hello,

if you are in debug mode, you can see where your exception is throw where an error occured in your gridview? So you can add an handler to this error using the call stack to see where the exception is throw? What is the cause of the exception? An llblgen call or a third method call?

Exceptions in separate posts.

I can't add a handler, as I haven't got the code that initiates the call. It's the LLBLGen code that attempts to save the changed entity to database.

The reason for the exception is a string too long to fit into the database field. Fair enough! I would like to handle the exception, though, and DetailsView works like a charm - GridView doesn't. Any idea what I might be doing wrong?

AndersJuul
User
Posts: 11
Joined: 17-Dec-2006
# Posted on: 07-Feb-2007 07:31:48   

MANY APOLOGIES - the fault was mine.

I'm using an open source component, InsertGrid, that derives from GridView.

It's doing some mumbo-jumbo that involves the RowUpdated event and somehow messes it up.

Replacing it with GridView solves the immediate problem - I need to to dive into the InsertGrid component and make it behave, in this regard, as the standard GridView.

Again, sorry for crying Wolf!

Anders, Denmark