System.OutOfMemoryException with large script.
Dan Guzman
Posts: 20
I successfully performed a data compare and saved the script to a file. My next task to run the script using the C# code below but I get an out of memory error when during the BlockLoader.Load method when try to load a moderately large script (100MB). Is there an alternative method to execute large scripts that avoids this error?
Thanks,
Dan
var blockLoader = new RedGate.Shared.SQL.ExecutionBlock.BlockLoader(@"C:MyScriptFile.sql"); var executionBlock = blockLoader.Load(); var executor = new RedGate.Shared.SQL.ExecutionBlock.BlockExecutor(); executor.ExecuteBlock(executionBlock, @".", "MyDatabase", true, "", "");
Thanks,
Dan
Comments
I don't know how the BlockLoader.Load method works, but I can imagine that if the script was getting loaded completely into RAM then 100GB could cause a few problems. If you're not already compiling to 64 bit, I'd suggest that you try it to see if it helps, but I don't know it it would completely fix the problem.
I'll ask the developers to see if I can get some clarification.
Redgate Software
I've double checked with the developers - Blockloader.Load loads the script all at once, so while 100 MB isn't inherently problematic, it does depend on what else is running and how much memory the computer has in total.
I'd recommend using ANTS Memory Profiler to examine the memory usage of your code in order to find out where the problem is. You'll get a 14 day free trial so that should give you enough time to do some meaningful diagnostics.
Redgate Software