G
Guest
Dear Community,
I'm using ADO.net to update a SQL Server 2005 table. The table has a an
aggregate primary key made of two integers. I use the typcial
SqlDataSet/SqlDataAdapter tools to perform updates and inserts, after an
initial call to da.FillSchema(). My select command is 'select * from t'
(where t is the table). My update and insert commands are both generated by
SqlCommandBuilder.
Before attempting any updates, I call t.Rows.Contains(<key>). Depending on
the result of the above, I either (1) use t.Rows.Find(<key>) and then set
some columns that are not part of the primary key or (2) call t.NewRow() set
the fields and then t.Rows.Add(). After a series of insert/update actions I
call da.Update(t).
My application works, as do most applications I have written in the past
using this simple model. However, I occasionally (~1/100,000) catch an
"Violation of PRIMARY KEY" exception when calling da.Update(t).
This baffles me since (1) no other programs or human users access the table,
(2) the updates are all performed in the same thread, (3) the call to
t.Rows.Add() never fails.
Has anyone experienced a similar issue and found the explanation?
I'm using ADO.net to update a SQL Server 2005 table. The table has a an
aggregate primary key made of two integers. I use the typcial
SqlDataSet/SqlDataAdapter tools to perform updates and inserts, after an
initial call to da.FillSchema(). My select command is 'select * from t'
(where t is the table). My update and insert commands are both generated by
SqlCommandBuilder.
Before attempting any updates, I call t.Rows.Contains(<key>). Depending on
the result of the above, I either (1) use t.Rows.Find(<key>) and then set
some columns that are not part of the primary key or (2) call t.NewRow() set
the fields and then t.Rows.Add(). After a series of insert/update actions I
call da.Update(t).
My application works, as do most applications I have written in the past
using this simple model. However, I occasionally (~1/100,000) catch an
"Violation of PRIMARY KEY" exception when calling da.Update(t).
This baffles me since (1) no other programs or human users access the table,
(2) the updates are all performed in the same thread, (3) the call to
t.Rows.Add() never fails.
Has anyone experienced a similar issue and found the explanation?