SOLUTION: Cannot insert explicit value for identity column in table 'SOMETABLE' when IDENTITY_INSERT is set to OFF.

2 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Oct 2011

    Posted 16 Apr 2015 Link to this post

    I've seen this exception referenced in a few threads with some users seemingly never getting it resolved. This particular solution is situation-specific but I wanted to post it here for anyone who may be experiencing the issue for the same reasons I was.

    Cannot insert explicit value for identity column in table 'YourTableNameHere' when IDENTITY_INSERT is set to OFF.

    In my particular case I was getting this same error because I had a field other than than the primary key set as the Identity Field!

    Pertinent fields from Table:

    Fieldname: ProjectId (Primary Key)
    Type: UniqueIdentifier
    RowGuid: True

    Fieldname: ClusterIndex
    Type: Int
    Identity Specification: Yes

    It was all but impossible to tell from the huge exception but it was actually the attempt to write to the ClusterIndex field that was throwing the exception!


    1) Open the rlinq file and in the designer click the offending field (ClusterIndex in my case). 

    2) In the Visual Studio Properties Editor set "Kind" to: "PersistentReadOnly".

    3) Save

    That's it! Now this field will NOT attempt to be written to when adding/updating records - and thus no more exception!

    Alternatively you could probably just remove the offending field from the entity model completely if you have no need for it in your code, etc.

    Hope this helps someone else!

  2. Doroteya
    Doroteya avatar
    497 posts

    Posted 21 Apr 2015 Link to this post

    Hello Michael,

    The solution you describe is the recommended one when the configuration matches the one on your side.

    Thank you for taking the time to investigate the issue and to share the outcome.

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
Back to Top