I have an import from Access table. That table is Category table, such as: - length - area...etc
That table from access has also an ID field, that sometimes can be 1,2,3,4,5, or sometimes 1,3,4,5... any combination.
I need to insert those values to my own ID field in the Server Table. Thus I tried to use identity insert on. Using this code:
using (var transaction = new TransactionScope())
{
dbContext.ExecuteCommand("TRUNCATE TABLE tbl_unitCat");
dbContext.ExecuteCommand("SET IDENTITY_INSERT tbl_unitCat ON");
foreach (DataRow row in table.Rows)//Rows coming from Access
{
tbl_unitCat currDBObj = new tbl_unitCat();
dbContext.tbl_unitCat.InsertOnSubmit(currDBObj);
//UnitCatID is the identity field
currDBObj.UnitCatID = row.ItemArray[0].ToInteger();
currDBObj.UnitCategory = row.ItemArray[1].ToString();
currDBObj.rawmat = (bool)row.ItemArray[2];
currDBObj.purchparts = (bool)row.ItemArray[3];
}
dbContext.SubmitChanges();
dbContext.ExecuteCommand("SET IDENTITY_INSERT tbl_unitCat OFF");
transaction.Complete();
}
It fails with this error: An explicit value must be specified for the identity column in the ' tbl_unitCat' table when IDENTITY_INSERT is set to ON or when a replication user into a NOT FOR REPLICATION identity column inserts.
The server I use is 2005. Looking at the SO similar posts, I found this MSDN Link
But that does not help me.
Any suggestions?