Does someone know what this error (An explicit value for the identity column in table \'HD_AANVRAAG_FASE\' can only be specified when a column list is used and IDENTITY_INSERT
You're missing a
SET IDENTITY_INSERT HD_AANVRAAG_FASE ON
before you run your insert. That's the exact cause of the error.
That said, inserting identity values explicitly is rare-- for example, used only when copying data from one table to another, or initializing a new table with explicit IDs. Usually you'll just want to omit identity values from your INSERT, which also avoids the error.
Your code contains
SET IDENTITY_INSERT HD_AANVRAAG_FASE OFF
at the end
But not a corresponding
SET IDENTITY_INSERT HD_AANVRAAG_FASE ON
at the start
why are you explicitly inserting these any way? Is it a synchronization task?
Since you aren't specifying the columns explicitly, I assume @fase_id
is being passed into an IDENTITY
column, which as the error indicates you can't do unless you force it via IDENTITY_INSERT
.
Usually, you let the DB generate this; specify the columns in the INSERT
and omit the identity column (and don't try to assign a value). The straight after the INSERT
your new id is available as SCOPE_IDENTITY()
.