You close the stream before ASP.NET MVC has finished reading from it. It will be closed after you leave the various usage blocks that will occur immediately after the return executed.
I donβt know how easy it is to do it. A better idea would be to write a custom Stream -derived class that wraps the stream returned by ADO.NET, and once the stream is exhausted, everything has to do ( Stream , reader, command, and connection).
This solution means you cannot use blocks, etc. I really don't like this, but right now I can't think of anything better. The requirements are complex in combination: you want streaming behavior and you need to get rid of the various resources that you have discovered.
source share