I have a strange problem. I have a simple application which copies some rows from a view in a sql server database to a table in another sql server database. It first check count of both source view and destination table, and if they differs, fetch data. This process re-occurs indefinitely using a timer.
The strange thing is, after some iterations, the result freeze and query return same old value on each run. But, if I close and reopen the application, the query return updated results.
I can't understand why this should happen. I am using LINQ to SQL. I've tried everything, convert linq db context to local variables, turn Object Tracking enabled or disabled, used transactions, but none of them works. Here is a code snippet of one of my functions (some casts and not needed codes are removed):
private void DoEvals()
{
[...]
dbDataContext db = new dbDataContext { ObjectTrackingEnabled = true };
localDataContext localdb = new localDataContext { ObjectTrackingEnabled = true };
List<Evaluation> evals = new List<Evaluation>();
try
{
var countOnline = (from x in db.Leads where x.StateCode == 0 select x).Count();
var countOffline = (from x in localdb.Evaluations select x).Count();
if (countOnline == countOffline)
{
return;
}
int stepCount = 500;
int steps = countOnline / stepCount;
for (int currentStep = 0; currentStep <= steps; currentStep++)
{
var q = (from l in db.Leads
where l.StateCode == 0
select l);
q = currentStep != steps ? q.Skip(currentStep * stepCount).Take(stepCount) : q.Skip(currentStep * stepCount);
evals.AddRange(q.ToList());
}
}
catch (Exception exc)
{
}
[...]
}
Do you have any idea on why this is happening? I have tried this application in two environments (remote view, local table - local view, local table), so I don't think this is because of caching in network nodes.