HELP.... Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to...


Author
Message
Ross L Rooker, Sr.(1)
Ross L Rooker, Sr.(1)
StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)
Group: StrataFrame Users
Posts: 50, Visits: 163
By default the table has an auto incrementing primary key. I need to be able to specify the primary key in the insert command. I checked the insert statement being sent to the backend and that insert statement looks good. I must be missing something. Why am I getting this error?

string strSQL = "set identity_insert tblIndividual ON ";
ExecuteNonQuery(strSQL);

this.PrimaryKeyIsAutoIncremented = false;
this.PrimaryKeyIsUpdatable = true;
               
this.Add();
this.Individual_First = "John";
this.Individual_Last = "Doe";
this.Individual_Key = 12345;      // Primary Key
this.Save();         ---------------> this line gets the error

-------------------------------------------------------------------------------------------------
DataLayerSavingException
  Cannot insert explicit value for identity column in table 'tblIndividual' when IDENTITY_INSERT is set to OFF.
SqlException
  Cannot insert explicit value for identity column in table 'tblIndividual' when IDENTITY_INSERT is set to OFF.

Source     : MicroFour StrataFrame Business
-------------------------------------------------------------------------------------------------




string strSQL = "set identity_insert tblIndividual OFF ";
ExecuteNonQuery(strSQL);

this.PrimaryKeyIsAutoIncremented = true;
this.PrimaryKeyIsUpdatable = false;
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ross,

Are you using using Stored Procedures (sp) to insert records in this BO?

If so and the sp was build by the SF DDT, then you will not be able to do what you want because the sp is already pre-build by the DDT with the auto-incremented setting being enabled.

Assuming you are using a sp, then you will have to change the settings in the BO to not use the stored procedure and then you method should work as expected.

Edhy Rijo

Ross L Rooker, Sr.(1)
Ross L Rooker, Sr.(1)
StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)StrataFrame User (148 reputation)
Group: StrataFrame Users
Posts: 50, Visits: 163
Not using a stored procedure.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search