I'm using .net, C# , LINQ, SQL Server 2012.
this work basically just insert many data into DB.
I found i missed about 7,000 rows over total 85,000 rows.
Then i go debug , i found there are some data with real duplicate key .
But most of their key is no existed in DB and the DB also return error as duplicate key.
any ideas please?
code is like this
try
{
resCnt++;
dbconn.table.AddObject(newRow);
dbconn.SaveChanges();
}
catch (Exception ex)
{
Console.WriteLine("DB fail ID:"+ newRow.id);
List< table> testRepeat=(
from da in dbconn.table
where da.id==table.id
select da
).Take(1).ToList();
if (testRepeat.Count() > 0)
{
Console.WriteLine(DateTime.Now+ "Repeated ID: " + table.id+" Saved at "+testRepeat.First().LastModified);
repeatCnt++;
}
else
{
Console.WriteLine("!!terrible!!");
}
there are some ids: 322476,438095 ....
the fist 322476 is exised , so the error say "322476 duplicate key "
as usual
but when i get 438095
to dbconn.SaveChanges();
the 438095 is no existed
it will go to the exception part the inner error still saying "322476 duplicate key... "
which at least should be "438095 duplicate key... "
then i click the variable row.id , it is 438095 ...