Solved

LINQTOSQL - Identity Insert is Set to Off???

Posted on 2008-10-26
3
563 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

Title # Comments Views Activity
Testing connection to sql 7 61
format nvarchar field as mm/dd/yyyy 4 78
SQL Server 2012 express 24 40
ms sql + top 1 for each customer 3 56
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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