Gracefully catching errors with LLBLGenProDataSource

Posts   
 
    
MAdams
User
Posts: 2
Joined: 29-Aug-2006
# Posted on: 29-Aug-2006 19:34:42   

Hi All,

I've been using LLBLGen Pro 2.0 for about a month now. I really like the new LLBLGenProDataSource objects but have a question.

There are a few errors I would like to catch more gracefully than the default MS web error page(See Example Below). These errors are "Unique Constraint Violations" and "Cannot insert a null into feild xxx" errors.

Again I'm using LLBLGenProDataSource with LivePersistance set to True and I want to catch the above errors and display freindlier error messages back to the user. Any Help would be appreciated.

Server Error in '/apps/NetMenu' Application.

An exception was caught during the execution of an action query: ORA-00001: unique constraint (NETMENU.NET_APPLICATION_PK) violated. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of an action query: ORA-00001: unique constraint (NETMENU.NET_APPLICATION_PK) violated. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ORMQueryExecutionException: An exception was caught during the execution of an action query: ORA-00001: unique constraint (NETMENU.NET_APPLICATION_PK) violated. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.] SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute() +594 SD.LLBLGen.Pro.ORMSupportClasses.BatchActionQuery.Execute() +75 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteActionQuery(IActionQuery queryToExecute, ITransaction containingTransaction) +64 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.AddNew(IEntityFields fields, ITransaction containingTransaction) +220 NetMenuDataObjects.EntityClasses.NetApplicationEntity.InsertEntity() in C:\dotnet\NetMenu\NetMenuCode\NetMenuDataObjects\EntityClasses\NetApplicationEntity.cs:685 SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, ITransaction transactionToUse) +573 SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(IPredicate updateRestriction, Boolean recurse) +666 NetMenuDataObjects.EntityClasses.NetApplicationEntity.Save(IPredicate updateRestriction, Boolean recurse) in C:\dotnet\NetMenu\NetMenuCode\NetMenuDataObjects\EntityClasses\NetApplicationEntity.cs:175 SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(Boolean recurse) +114 SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteInsert(IDictionary values) +198 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +72 System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +390 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +623 System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +109 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

MAdams
User
Posts: 2
Joined: 29-Aug-2006
# Posted on: 29-Aug-2006 21:41:02   

Sorry all but after some experimenting I found the solution. I'll post here in case anyone needs it.

In the detailview or gridview inserting/updating events check for the errors you want to prevent and then cancel the event.

My code looked something like this:

protected void dvApplication_ItemInserting(object sender, DetailsViewInsertEventArgs e) { NetApplicationEntity AppEnt = new NetApplicationEntity(e.Values[ NetApplicationFields.AppName.Name].ToString()); if (!AppEnt.IsNew) { e.Cancel = true; this.lblError.Visible = true; this.lblError.Text = "Application " + AppEnt.AppName + " already exists."; return; } }

The e.cancel = true was the key to stopping the llblgenprodatasource from continuing with the insert in this case.

Thanks