I was trying to copy (copy with headers) around 20,000 rows from an output grid of a query into an excel sheet. And this "System.OutOfMemoryException" occurred.
This might be due to the size . Not necessarily the number of rows it could be number of columns and data type. Try dividing the result set and pasting it