Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3218086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:29:12+00:00 2026-05-17T15:29:12+00:00

An SQL table has auto increment property set for the primary key AnnotationID of

  • 0

An SQL table has auto increment property set for the primary key AnnotationID of INT type.

The Silverlight application WCF service code:

    public void InsertImageAnnotation(int imageId, string imagePath)
    {
        DataClassDataContext db = new DataClassDataContext();
        ImageAnnotation row = new ImageAnnotation();

        row.ImageID = imageId;//foreign key
        row.ImagePath = imagePath;

        db.ImageAnnotations.InsertOnSubmit(row);
        db.SubmitChanges();            
    }

An exception is thrown on db.SubmitChanges() with the message: Cannot insert explicit value for identiy column in the table ImageAnnotations when IDENTITY_INSERT is set to OFF.

I am not specifying the primary key, which is supposed to be the identity key, becasue I expect the db would take care of the auto-incrementing the primary key value.

The table create script is here:

USE [ImagingSericesDB]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[ImageAnnotations](

[AnnotationID] [int] IDENTITY(0,1) NOT NULL,

[ImageID] [int] NOT NULL,

[ImagePath] [text] NULL,

CONSTRAINT [PK_ImageAnnotations] PRIMARY KEY CLUSTERED

(
[AnnotationID] ASC

)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[ImageAnnotations] WITH CHECK ADD CONSTRAINT [FK_ImageAnnotations_Images] FOREIGN KEY([ImageID]) REFERENCES [dbo].[Images] ([AIImageID])
GO

ALTER TABLE [dbo].[ImageAnnotations] CHECK CONSTRAINT [FK_ImageAnnotations_Images]

What I am missing in my service call syntax? How can I specify or execute IDENTITY_INSERT to ON in my service code above? What is the syntax?
Thanks a lot,
Val

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:29:13+00:00Added an answer on May 17, 2026 at 3:29 pm

    You are sending a value for the identity field when it wants to create it automatically. That’s what the error message means. Check to see what code you are generating to see what the problem is. It is also entirely possible the problem is not in your insert but in an insert from a trigger, so check that as well.

    Under no circumstances should you set the identity insert to on. Either you are sending an identity value that you don’t need to send or you shouldn’t be using an identity to generate the id. Identity insert is used generally only by dbas to insert legacy data before a databse goes live. It should very rarely be used at any other time and never by someone who has to ask the syntax. This is a command that can royally screw up your database, do not use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an table which use an auto-increment field (ID) as primary key. The
I have a T-SQL table variable (not a table) which has an auto incrementing
I have a table in SQL Server 2005 which has three columns: id (int),
I have a MySQL table of users whose primary key is an auto-incrementing integer
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
In SQL Server or maybe other databases, if a column is auto increment int
I have a SQL table which has a number of fields ID | Value
In SQL Server 2005 I have an id field in a table that has
I am selecting from a table that has an XML column using T-SQL. I
I have a table in SQL server that has the normal tree structure of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.