Previous Topic: ID/Sequence Column SupportNext Topic: Multiple Foreign Key Constraints


Failed to Insert because IDENTITY_INSERT is Set to Off

Valid on MSSQL only

Symptom:

The message Failed to Insert because IDENTITY_INSERT is Set to Off appears when you create an account. This message occurs because your database table has IDENTITY_INSERT set to off.

Solution:

Write a stored procedure to create an account, and write scripts that set IDENTITY_INSERT on before the insert operation and then sets IDENTITY_INSERT off. Do the following:

  1. Write a one-line stored procedure with timing=PRE (Before) that sets IDENTITY_INSERT [ database. [ owner. ] ] { table } on.
  2. Write another one-line stored procedure with timing=POST (After) that sets IDENTITY_INSERT [ database. [ owner. ] ] { table } off.