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

Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'cusCustomControlMaster' when IDENTITY_INSERT is set to OFF.

How do I fix this? Can I add something in my Query or what do I need to set?
INSERT INTO dbo.cusCustomControlMaster 
		(
		CustomControlMasterID,
		CustomControlContainerID,
		nType,
		cCaption,
		nOrder,
		nTop,
		nLeft,
		nWidth,
		nHeight,
		cEnabled,
		cActive,
		cLabelAbove,
		mDefault,
		nAlignment,
		nStyle,
		nLength,
		cFormat,
		cInput,
		nRequired,
		TableName,
		CustomMLTableNamesID,
		Created,
		CreatedBy,
		LastModified,
		LastModifiedBy
		) 
VALUES 
	( 
	/*CustomControlMasterID - int*/ 17,
	/* CustomControlContainerID - int */ 5,
	/* nType - int */ 10,
	/* cCaption - varchar(80) */ 'Medical',
	/* nOrder - int */ 8,
	/* nTop - int */ 16,
	/* nLeft - int */ 35,
	/* nWidth - int */ 341,
	/* nHeight - int */ 21,
	/* cEnabled - char(2) */ '-1',
	/* cActive - char(2) */ '-1',
	/* cLabelAbove - char(2) */ '0',
	/* mDefault - text */ NULL,
	/* nAlignment - int */ NULL,
	/* nStyle - int */ NULL,
	/* nLength - int */ NULL,
	/* cFormat - varchar(80) */ NULL,
	/* cInput - varchar(80) */ NULL,
	/* nRequired - smallint */ 0,
	/* TableName - varchar(30) */ NULL,
	/* CustomMLTableNamesID - int */ 1,
	/* Created - datetime */ GETDATE(),
	/* CreatedBy - varchar(30) */ 'CySolutions',
	/* LastModified - datetime */ GETDATE(),
	/* LastModifiedBy - varchar(50) */ 'CySolutions' 
	)

Open in new window

LVL 7
Jeff SAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
If CustomControlMasterID is the identity column then do not specify in the insert statement.  
next value will be added by itself.
INSERT INTO dbo.cusCustomControlMaster 
		(
		CustomControlContainerID,
		nType,
		cCaption,
		nOrder,
		nTop,
		nLeft,
		nWidth,
		nHeight,
		cEnabled,
		cActive,
		cLabelAbove,
		mDefault,
		nAlignment,
		nStyle,
		nLength,
		cFormat,
		cInput,
		nRequired,
		TableName,
		CustomMLTableNamesID,
		Created,
		CreatedBy,
		LastModified,
		LastModifiedBy
		) 
VALUES 
	( 
	/* CustomControlContainerID - int */ 5,
	/* nType - int */ 10,
	/* cCaption - varchar(80) */ 'Medical',
	/* nOrder - int */ 8,
	/* nTop - int */ 16,
	/* nLeft - int */ 35,
	/* nWidth - int */ 341,
	/* nHeight - int */ 21,
	/* cEnabled - char(2) */ '-1',
	/* cActive - char(2) */ '-1',
	/* cLabelAbove - char(2) */ '0',
	/* mDefault - text */ NULL,
	/* nAlignment - int */ NULL,
	/* nStyle - int */ NULL,
	/* nLength - int */ NULL,
	/* cFormat - varchar(80) */ NULL,
	/* cInput - varchar(80) */ NULL,
	/* nRequired - smallint */ 0,
	/* TableName - varchar(30) */ NULL,
	/* CustomMLTableNamesID - int */ 1,
	/* Created - datetime */ GETDATE(),
	/* CreatedBy - varchar(30) */ 'CySolutions',
	/* LastModified - datetime */ GETDATE(),
	/* LastModifiedBy - varchar(50) */ 'CySolutions' 
	)

Open in new window

Om PrakashCommented:
If you want to explicitly add value 17
(Assuming it is not present then you can set SET IDENTITY_INSERT ON)

SET IDENTITY_INSERT dbo.cusCustomControlMaster  ON
GO
-- Try to insert an explicit ID value of 3.
INSERT INTO dbo.cusCustomControlMaster  (CustomControlContainerID, NType) VALUES (17, 10)
GO
SET IDENTITY_INSERT dbo.cusCustomControlMaster  OFF
GO

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeff SAuthor Commented:
om prakash p
Thank you. I am doing about 30 rows and would like to do these in one script, can I union them all together or in one script somehow? (See below).

SET IDENTITY_INSERT dbo.cusCustomControlMaster  ON
GO
INSERT INTO dbo.cusCustomControlMaster  
		(
		CustomControlMasterID,CustomControlContainerID,nType,cCaption,nOrder,nTop,nLeft,nWidth,nHeight,cEnabled,cActive,cLabelAbove,mDefault,nAlignment,nStyle,nLength,cFormat,cInput,
		nRequired,TableName,CustomMLTableNamesID,Created,CreatedBy,LastModified,LastModifiedBy
		)  
		VALUES 
		(
		17,5,10,'Medical',8,16,35,341,21,-1,-1,0,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,1,GETDATE(),'cysolutions',GETDATE(),'cysolutions'
		)
--		VALUES
--		(
--		18,5,10,'Vision',9,40,35,341,21,-1,-1,0,NULL,NULL,NULL,NULL,NULL,NULL,0,NULL,2,	GETDATE(),'cysolutions',GETDATE(),'cysolutions'
--		)

GO
SET IDENTITY_INSERT dbo.cusCustomControlMaster  OFF
GO

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.