Is there a way to control memory usage of C # DataTable

I am writing a tool to copy data to SQL Server using C # SqlBulkCopy. For reliability reasons, I load each batch of data into the DataTable (so that later I can retry in the same batch if the insert fails) and users can specify the batch size. Now the problem is that the user sets the batch size to a very large value, the memory consumption of the DataTable will be huge and even throw an OutOfMemoryException.

One solution I can think of is to sum the data size as I am caching the data in the DataTable and control the size there. Are there better approaches?

Thank.

+3


source to share





All Articles