On 26.01.2012 22:37, Tony wrote:
> I don't understand this. I mean if I set a breakpoint on this line
> object s1 = param.Value;
> the select statement is completed so the param.Value should be available
> but it isn't.
No, the select has not yet completed. The reader uses deferred
execution. Similar to LINQ. Example:
int[] arr = new int[] {1,2};
int var = 0;
var transformed = arr.Select(i => var = i+1);
So what is the value of var here? It is still 0, because the selection
has not even begun so far.
> So why has not the statement completed when I access this line object s1
> = param.Value ?
Lets say your select will return 6GB of data and you are running on a 32
bit platform. If the select has completed, the 6GB data have to be
stored somewhere. In memory is impossible. So what should the database
driver do? Create a temp file? Where?
Furthermore, your application can not start with the processing of the
/first/ result line unless the 6GB have been retrieved over the network,
if it waits for the select to complete.
The DB reader is more like a file stream. It uses some buffering, but it
never holds the entire result set in memory unless it is small.
You always should know that. Think of a database connection pool. If you
fetch a connection from the pool, execute a query, keep the reader open
and then pass the connection back into to pool before the reader has
completed, then you will run into serious trouble. Most database drivers
do not support multiplexed reads over one connection, i.e. you can't
have more than one open reader per connection at a time.
Marcel