steven

steven

  • NA
  • 24
  • 41.5k

How the method SqlDataReader.Read() work?

Aug 10 2011 5:26 AM
this is the reflector code, basically, the data should be come from Socket, right? Then, how about the middle process? i want to know some details. socket   -----------(middle process)-------------> SqlDataReader.GetString(...)

Can someone explain more? Thanks in advance.



public override bool Read()
{
  return this.ReadInternal(true);
}


private bool ReadInternal(bool setTimeout)
{
   
bool flag;
    SqlStatistics statistics
= null; IntPtr ptr; Bid.ScopeEnter(out ptr, "<sc.SqlDataReader.Read|API> %d#", this.ObjectID);
    RuntimeHelpers.PrepareConstrainedRegions();
   
try
    {
        statistics
= SqlStatistics.StartTimer(this.Statistics);
       
if (this._parser == null)
        {
           
goto Label_017B;
        }
       
if (setTimeout)
        {
           
this.SetTimeout();
        }
       
if (this._dataReady)
        {
           
this.CleanPartialRead();
        }
       
this._dataReady = false;
        SqlBuffer.Clear(
this._data);
       
this._nextColumnHeaderToRead = 0;
       
this._nextColumnDataToRead = 0;
       
this._columnDataBytesRemaining = -1L;
       
if (this._haltRead)
        {
           
goto Label_016A;
        }
       
if (this.HasMoreRows())
        {
           
while (this._stateObj._pendingData)
            {
               
if (this._altRowStatus != ALTROWSTATUS.AltRow)
                {
                   
this._dataReady = this._parser.Run(RunBehavior.ReturnImmediately, this._command, this, null, this._stateObj);
                   
if (!this._dataReady)
                    {
                       
continue;
                    }
                }
               
else
                {
                   
this._altRowStatus = ALTROWSTATUS.Done;
                   
this._dataReady = true;
                }
               
break;
            }
           
if (this._dataReady)
            {
               
this._haltRead = this.IsCommandBehavior(CommandBehavior.SingleRow);
               
return true;
            }
        }
       
if (!this._stateObj._pendingData)
        {
           
this.CloseInternal(false);
        }
       
goto Label_018E;
    Label_010E:
       
this._dataReady = this._parser.Run(RunBehavior.ReturnImmediately, this._command, this, null, this._stateObj);
    Label_012E:
       
if (this._stateObj._pendingData && !this._dataReady)
        {
           
goto Label_010E;
        }
       
if (this._dataReady)
        {
           
this.CleanPartialRead();
        }
       
this._dataReady = false;
        SqlBuffer.Clear(
this._data);
       
this._nextColumnHeaderToRead = 0;
    Label_016A:
       
if (this.HasMoreRows())
        {
           
goto Label_012E;
        }
       
this._haltRead = false;
       
goto Label_018E;
    Label_017B:
       
if (this.IsClosed)
        {
           
throw ADP.DataReaderClosed("Read");
        }
    Label_018E:
       
return false;
    }
   
catch (OutOfMemoryException exception3)
    {
       
this._isClosed = true;
        SqlConnection connection3
= this._connection;
       
if (connection3 != null)
        {
            connection3.Abort(exception3);
        }
       
throw;
    }
   
catch (StackOverflowException exception2)
    {
       
this._isClosed = true;
        SqlConnection connection2
= this._connection;
       
if (connection2 != null)
        {
            connection2.Abort(exception2);
        }
       
throw;
    }
   
catch (ThreadAbortException exception)
    {
       
this._isClosed = true;
        SqlConnection connection
= this._connection;
       
if (connection != null)
        {
            connection.Abort(exception);
        }
       
throw;
    }
   
finally
    {
        SqlStatistics.StopTimer(statistics);
        Bid.ScopeLeave(
ref ptr);
    }
   
return flag;
}

 


Answers (1)