Labels

slider

Recent

Navigation

Exception: System Data Entity Infrastructure DbUpdateException

System.Data.Entity.Infrastructure.DbUpdateException, system.data.entity.infrastructure.dbupdateexception' occurred in entityframework.dll, system.data.entity.infrastructure.dbupdateexception error

Introduction

I was engaged on MVC application utilisation Entity Framework, MVC and Jquery. I hit the Save button to save corresponding values into database, however this did,'t happen fine as common, I got the special error An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code.

Error Description

An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code

Solution I

When I started operating to resolve issue, debugging deeply and found of stack trace message then I found that this issue was because of database table identity off.

Table Identity off

I simply set table Identity on and once more tried to save relevant values into database, this time it worked fine for me.
Table Identity On


Solution II

This Error A special case of sort An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code yet was not took care of in client code likewise comes when duplicte value entering in primary key so you have to cross check to conquer this mistake.

Need to Refresh Entity Framework Model After Database Change

Once you set primary key in database then when you would like to refresh your entity framework model through front end code.

Conclusion

Another superb expertise of MVC, Entity Framework, Jquery application. Every time, in each new application usually comes new problems. From these issues, we learnt another lesson each time and smoothing approach to next time. Above, I have clarified in subtle element by what method would we be able to determine issue of A special case of sort An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code. In the event that despite everything you locate the same issue, kindly keep in mind to think of me here.

Suggested Reading

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

16 comments:

  1. i set identity is yes then also it give me same error msg :(

    ReplyDelete
    Replies
    1. then add entity framework model again, I think your entity model does not refreshed yet. if you still face the same error then let me know.

      Delete
  2. Nice i have encountered with the same error and it resolved by your solution, what i have did that i have removed field to become primary key because i was unable to on the identity.

    ReplyDelete
  3. This solved all of my problems. Thank you so much!

    ReplyDelete
    Replies
    1. Well done! keep reading more on Entity Framework.

      Delete
  4. is give me the some errors message plzz help me ? I'm beginner .

    ReplyDelete
    Replies
    1. Did you set identity on in your table, EF requires primary key necessary, it did not fixed this issue then after remove your old entity framework model and add entity framework again in your application.

      Delete
  5. hello ,, i have the same error but i couldn't solve it with your solution because the type of my primary key is nvachar so can you help me please ????

    ReplyDelete
    Replies
    1. Yes, you need to set primary key in your database table first because ORM EF can't work without relations. EF is totally helpless without relationships between tables.

      Delete
  6. I am getting the same error even though i have the primary key with identity property set to true, what to do? i hope you can help me with this i am kind of a beginner.

    ReplyDelete
    Replies
    1. Can you confirm me that you are not inserting duplicate value in primary key in your database table.

      Delete
  7. I give the type uniqueidentifier.So What to do?

    ReplyDelete