@@ -39,15 +39,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
3939 {
4040 buffer = null ;
4141
42- ( bool isAvailable , bool isStarting , _ ) = stateObj . GetSnapshotStatuses ( ) ;
42+ ( bool isAvailable , bool isStarting , bool isContinuing ) = stateObj . GetSnapshotStatuses ( ) ;
4343
4444 List < byte [ ] > cachedBytes = null ;
4545 if ( isAvailable )
4646 {
4747 cachedBytes = stateObj . TryTakeSnapshotStorage ( ) as List < byte [ ] > ;
48- if ( isStarting )
48+ if ( cachedBytes != null && ! isStarting && ! isContinuing )
4949 {
50- cachedBytes = null ;
50+ stateObj . SetSnapshotStorage ( null ) ;
5151 }
5252 }
5353
@@ -56,13 +56,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
5656 cachedBytes = new List < byte [ ] > ( ) ;
5757 }
5858
59+
5960 // the very first length is already read.
6061 TdsOperationStatus result = parser . TryPlpBytesLeft ( stateObj , out ulong plplength ) ;
6162 if ( result != TdsOperationStatus . Done )
6263 {
6364 return result ;
6465 }
6566
67+
6668 // For now we only handle Plp data from the parser directly.
6769 Debug . Assert ( metadata . metaType . IsPlp , "SqlCachedBuffer call on a non-plp data" ) ;
6870 do
@@ -103,7 +105,10 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
103105
104106 if ( returnAfterAdd )
105107 {
106- stateObj . SetSnapshotStorage ( cachedBytes ) ;
108+ if ( isStarting || isContinuing )
109+ {
110+ stateObj . SetSnapshotStorage ( cachedBytes ) ;
111+ }
107112 return result ;
108113 }
109114
0 commit comments