OracleBulkCopy memory leak (OutOfMemory exception)

Below is the code I used to get the data as an array from temp tableTable to destTable in Oracle Database. There are about 2 million records in the DataTable.

using (OracleBulkCopy bulkCopy = new OracleBulkCopy(VMSDATAConnectionString)) { try { foreach (OracleBulkCopyColumnMapping columnMapping in columnMappings) bulkCopy.ColumnMappings.Add(columnMapping); bulkCopy.DestinationTableName = destTableName; //bulkCopy.BatchSize = dataTable.Rows.Count; //bulkCopy.BulkCopyTimeout = 100; int defaultSize = 5000; int.TryParse(ConfigurationManager.AppSettings["OracleBulkCopyBatchSize"], out defaultSize); bulkCopy.BatchSize = defaultSize; int timeOut = 100; int.TryParse(ConfigurationManager.AppSettings["OracleBulkCopyTimeout"], out timeOut); bulkCopy.BulkCopyTimeout = timeOut; Console.WriteLine("Bulk insert from {0} to {1} started at: {2}\r\nBatchSize : {3}, BulkCopyTimeout : {4} ", dataTable.TableName, destTableName, DateTime.Now.ToString("HH:mm:ss"), bulkCopy.BatchSize.ToString(), bulkCopy.BulkCopyTimeout.ToString()); bulkCopy.WriteToServer(dataTable); Console.WriteLine("Bulk insert from {0} to {1} finished at: {2}", dataTable.TableName, destTableName, DateTime.Now.ToString("HH:mm:ss")); } catch (Exception ex) { Console.WriteLine("Error happened during bulk copy from {0} to {1}\r\nBatchSize : {2}, BulkCopyTimeout : {3}\r\n Error message {4}", dataTable.TableName, destTableName, bulkCopy.BatchSize.ToString(), bulkCopy.BulkCopyTimeout.ToString(), ex.ToString()); bulkCopy.Close(); bulkCopy.Dispose(); } } 

But this raises the following exception: enter image description here

The server that runs this data loading process definitely has enough memory, it looks like the database server (Linux) does not have enough memory. The following is a screenshot of the database server memory: enter image description here

Can anyone help with this problem? Thanks.

+2
c # oracle memory-leaks sqlbulkcopy bulkinsert
source share
1 answer

Found the root cause, exe runs at 32 bits and has a limit of 1.5 GB of memory. You need to change the target platform and replace Oracle.DataAccess.dll with a 64-bit version.

There is also an alternative solution: load data in batch mode so that it does not exceed the limit of 1.5 GB of memory.

Update:

"MEMORY LEAK WITHING ORACLEBULKCOPY": the oracle volume copy has some error that causes a memory leak, this occurs when BatchSize is less than the datatable size. You must modify BatchSize or upgrade ODAC to a higher version.

Link: https://community.oracle.com/message/4593452#4593452

+4
source share

All Articles