0

I have a programm in C# which downloads data from 4 sources (2 excel sheets,oracle and access database) and calculate them against each other. In the result I have some big results, I keep the results in List. Amount of rows in the result equals approximately 120.000. One row is about 10MB. The result inserts into access database.

How do I insert this list into my databse? Can someone give me an example?

Now I insert rows into table one by one. It costs me about 3 hours to do that.

Community
  • 1
  • 1
Bushuev
  • 557
  • 1
  • 10
  • 29

1 Answers1

2

Use some kind of bulk insert. If your use entity framework to work with your db's something like this is what you need. Max out the timeout as well.

 using (var transactionScope = new System.Transactions.TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                try
                {
                    ctx.BulkInsert(productsToSync, new BulkInsertOptions()
                    {
                        TimeOut = 10 * 60 * 1000
                    });
                    await ctx.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    SystemLogManager.AddDataSyncErrorLog(ex);
                }
                finally
                {
                    transactionScope.Complete();
                }
            }
tjones0808
  • 146
  • 12