Solved

LINQTOSQL - Identity Insert is Set to Off???

Posted on 2008-10-26
3
561 Views
Last Modified: 2012-06-27
I have a problem doing an insert via LinqToSql within a table (sql server 2005) that has an identity column (autoincrement).

Error generated is:
Cannot insert explicit value for identity column in table 'sometable' when IDENTITY_INSERT is set to OFF.

Question is, how to do either turn it on in c# code or better yet, keep it on all the time?
0
Comment
Question by:ChiBella
  • 2
3 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22808252
What you need to do is NOT specify the identity column in your insert and have it auto generate the value.  That is the purpose of identity fields.  
0
 

Author Comment

by:ChiBella
ID: 22808263
I know this...I'm getting error without any specification to the column.

0
 

Accepted Solution

by:
ChiBella earned 0 total points
ID: 22808282
ok, in case anyone else makes the mistake I just did...

If you make a change like adding an identity to a column in sql server, you must remove the table from your dbml and add it back...otherwise you get this error.

0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question