4

I'm using LINQ to SQLto import old DBF files into MSSQL. I'm reading all rows and adding them to database using ctx.MyTable.InsertOnSubmit(row)

After reading phase is completed I have around 100 000 pending inserts. ctx.SubmitChanges() naturally is taking a long time.

Is there any way to track progress of the ctx.submitchanges()? Can ctx.Log somehow be used for this purpose?

Update: Is it possible to use ctx.GetChangeSet().Inserts.Count and track insert statements using the Log?

Dividing ctx.SubmitChanges() into smaller chunks is not working for me, because I need transaction, all or nothing.

Update 2: I've found nice class ActionTextWriter using which I will try to count inserts.

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

Update 3:

I've build first code prototype, it's not optimized. It seems to be working :)

ctx.Log = new ActionTextWriter(s => {
 counter += s.Split(' ').Count(w => w.ToUpper() == "INSERT");
 ReportProgress(counter);
});
Emir
  • 1,586
  • 3
  • 16
  • 32
  • Same question here: http://stackoverflow.com/questions/648379/how-can-i-get-a-percentage-of-linq-to-sql-submitchanges – as-cii Dec 30 '10 at 15:34

1 Answers1

0

I've managed to get progress informations by parsing log and using ActionTextWriter

http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

ctx.Log = new ActionTextWriter(s => {
    if (s.StartsWith("INSERT INTO"))
        insertsCount++;
});
Emir
  • 1,586
  • 3
  • 16
  • 32