Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to deal with error on update?
Message
 
 
To
13/03/2010 12:41:43
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454304
Message ID:
01454316
Views:
33
Hi Bonnie,

Now, after re-reading the blog III again, I see how you are handling the error. Very nice. I am not sure why you used the name Start() though. To me, it seems more like .End() <g> since you call it at the end of methods. But it gives me now something to work on. By the way, in your real application did you return actual error to the UI? My customers will be very confused by these types of messages. I am thinking, therefore, to create a table translating the error message into less confusing and more readable English sentence. I will probably (just thinking out loud) put an ID into the name of a constraint to use as a key to find a corresponding entry in a table. I have not thought out how I will do it and if this table will be a real table or some kind of a text file.


>Hi Dmitry,
>
>Thanks for referring to me as "famous". <g>
>
>So, if you used my example totally as your DAL, then you probably had to tweak it a bit (for lurkers, I believe Dmitry is referring to Part III of my DataAccess series: http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html).
>
>I noticed in the Start() method that it handles exceptions by this statement:
>
this.AddToErrorMessage(e);
>And of course there is no AddToErrorMessage() method in my example. There is, however, an ErrorMessage property in the original BBDataAccess class shown in Part II: http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
>
>If your Start() method returns a false, you should be able to access the ErrorMessage property and do something with it, like return it to your UI.
>
>Does this help?
>
>~~Bonnie
>
>
>>Hi,
>>
>>How do you deal with cases when database update (SQL Server) fails (e.g. constraints)? Here is a code from the DAL class that updates the database (this is not my code; I borrowed it from a blog of a famous person here <g>):
>>
>>
>>       protected void SaveTable(DataTable Table, string SaveProc)    
>>        {        
>>            foreach (DataRow row in Table.Rows)
>>            {            
>>                this.SetAllParameters(row);
>>                this.ExecuteCommand(SaveProc);
>>            }    
>>        }
>>
>>// The problem occurs in method ExecuteCommand.  And the ExecuteCommand method looks like this:
>>//  simplified
>>protected void ExecuteCommand(string StoredProcName)    
>>        {        
>>
>>            try         
>>            {             
>>                this.oCommand.ExecuteNonQuery();
>>            }        
>>            catch (Exception ex)
>>            {
>>                // !! This is where I get the error that Breaks the code.  
>>                throw ex;
>>            }        
>>         }
>>
>>
>>
>>What I would like is to be able to return the error message back to the UI layer to be displayed.
>>
>>TIA for any suggestions.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform