I have a WPF application that I have converted from adding records with stored procs and change to add records with Entity Framework.
Adding records into Sql 2012 works fine on the development machine with the entity framework. The production has sql 2008 and I am not able to add records using entity framework. I get the error message:
Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is set to OFF
What should I look for to solve this problem?
Arne Garvander
Certified Geek
Professional Data Dude
Minnesota
I don't think I understand your answer. For 20 years I have seen identity column automatically getting populated. Maybe the entity framework is trying to insert an explicit value behind the scene, by misstake.
Arne Garvander
Certified Geek
Professional Data Dude
Minnesota
I found my own problem. A SQL identity was missing from development database. Nowhere in my Entity Framework database designer could I see my problem. I had to go into SQL server where I found my error.
Arne Garvander
Certified Geek
Professional Data Dude
Minnesota
Marked as answer by Arne Garvander on Jul 24, 2012 06:23 PM
Arne Garvand...
Member
111 Points
105 Posts
Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is set t...
Jul 23, 2012 07:18 PM|LINK
I have a WPF application that I have converted from adding records with stored procs and change to add records with Entity Framework.
Adding records into Sql 2012 works fine on the development machine with the entity framework. The production has sql 2008 and I am not able to add records using entity framework. I get the error message:
Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is set to OFF
What should I look for to solve this problem?
Certified Geek
Professional Data Dude
Minnesota
adamturner34
Contributor
3844 Points
963 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 07:20 PM|LINK
In your stored procedure, you have to add the line:
SET IDENTITY_INSERT ON
Arne Garvand...
Member
111 Points
105 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 07:23 PM|LINK
I can't do that because I am not using a stored proc. I am using the Entity Framework,
Certified Geek
Professional Data Dude
Minnesota
Rohit Rao
Participant
1869 Points
357 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 07:25 PM|LINK
Check the Auto Generated Value property of the column in you Entity FrameWork designer :
Arne Garvand...
Member
111 Points
105 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 07:32 PM|LINK
I don't think I understand your answer. For 20 years I have seen identity column automatically getting populated. Maybe the entity framework is trying to insert an explicit value behind the scene, by misstake.
Certified Geek
Professional Data Dude
Minnesota
Rohit Rao
Participant
1869 Points
357 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 07:39 PM|LINK
you dont need to provide identity column values in entity framework while inserting.
hope this will help you : http://stackoverflow.com/questions/9622654/entity-framework-issue-with-identity-insert-cannot-insert-explicit-value-for
Arne Garvand...
Member
111 Points
105 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 23, 2012 08:04 PM|LINK
I am using Visual Studio 2010 professional and Visual Studio 2010 c# Express. My properties does not look the same as yours. What are you using?
Certified Geek
Professional Data Dude
Minnesota
Arne Garvand...
Member
111 Points
105 Posts
Re: Cannot insert explicit value for identity column in table 'Problem' when IDENTITY_INSERT is s...
Jul 24, 2012 06:22 PM|LINK
I found my own problem. A SQL identity was missing from development database. Nowhere in my Entity Framework database designer could I see my problem. I had to go into SQL server where I found my error.
Certified Geek
Professional Data Dude
Minnesota