SQL Server – Increase Max Server Memory to Fix OutOfMemoryException

errorsimportmemorysql server

I am not very experienced so please bear with me.

I have been attempting to import a 2500 MB and 3800 MB CSV into SQL Server 2016. Unfortunately I keep getting the System.OutOfMemoryException error. My computer has 8.00 GB RAM so I figured I would just increase the max server memory from the default up to 4000 MB. For some reason though each time I try to change the max server memory to make it higher it changes back to default the moment I press OK. How do I fix this problem?

I am using BULK INSERT to import the data. The BATCHSIZE, KILOBYTES_PER_BATCH, and ROW_PER_BATCH arguments are not set.

UPDATE

I have decided to split up my CSV document so that I can import less of it at a time. Unfortunately by the time I try to import the last piece of my CSV the error shows up again.

UPDATE

I have managed to substantially increase the max server memory to 4 GB. However this has not fixed the problem.

Best Answer

The System.OutOfMemoryException error that you are seeing means there was a problem with SQL Server Management Studio, not with the amount of memory on the server itself. One easy way to trigger this error is to simply run a SELECT query on a large table. If the table is too large then the results grid will take up too much memory and you'll see the error.

It's not clear to me why you would experience this error when importing data, but raising max server memory is not the right fix. I recommend trying BULK INSERT after setting the BATCHSIZE, KILOBYTES_PER_BATCH, or ROW_PER_BATCH arguments. That will limit the amount of data sent in a single transaction. You could also try importing the data through bcp. You don't even need SSMS open for that.