DBUpdate Exception in LINQ to Entity Framework RRS feed

  • Question

  • Hi ......

    I'm using linq to entity framework in c# windows application and if the application raise a DBUpdateException that are handled by raising message box to user , but if i try to do other something on database by linq before close and reopen the application it will raise another exception for a valid operations .

    is there is any way to refresh context after a DBUpdateException occured ?

    Thanks for attention .

    • Moved by Caillen Wednesday, February 12, 2014 8:30 AM
    Tuesday, February 11, 2014 7:12 AM

All replies

  • After an exception occurs yo uhave to be careful not to access any objects that caused the exception.  You do not have to exist the application.  The code should not cause another exception.  If another exception occurs press the link to copy detainls to clipboard and paste into notepad.  Try to determine the root cause of 2nd exception.


    Tuesday, February 11, 2014 3:17 PM
  • is there is any way to refresh context after a DBUpdateException occured ?

    May be you need to be opening and closing connection explicitly by using a try/finally.



    do something






    That way the connection is close no matter if the code blows up or is successful encompassed by the try/finally.

    You reset by opening the connection again on the trip back to use the code to access the database. 

    Saturday, February 15, 2014 1:33 PM
  • Without see the actual code we would be taking a guess. 

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Saturday, February 15, 2014 2:48 PM