@@ -671,67 +671,71 @@ override public void Prepare()
671
671
// between entry into Execute* API and the thread obtaining the stateObject.
672
672
_pendingCancel = false ;
673
673
674
-
675
674
SqlStatistics statistics = null ;
676
- statistics = SqlStatistics . StartTimer ( Statistics ) ;
675
+ try
676
+ {
677
+ statistics = SqlStatistics . StartTimer ( Statistics ) ;
677
678
678
- // only prepare if batch with parameters
679
- if (
680
- this . IsPrepared && ! this . IsDirty
681
- || ( this . CommandType == CommandType . StoredProcedure )
682
- || (
683
- ( System . Data . CommandType . Text == this . CommandType )
684
- && ( 0 == GetParameterCount ( _parameters ) )
685
- )
679
+ // only prepare if batch with parameters
680
+ if (
681
+ this . IsPrepared && ! this . IsDirty
682
+ || ( this . CommandType == CommandType . StoredProcedure )
683
+ || (
684
+ ( System . Data . CommandType . Text == this . CommandType )
685
+ && ( 0 == GetParameterCount ( _parameters ) )
686
+ )
686
687
687
- )
688
- {
689
- if ( null != Statistics )
688
+ )
690
689
{
691
- Statistics . SafeIncrement ( ref Statistics . _prepares ) ;
690
+ if ( null != Statistics )
691
+ {
692
+ Statistics . SafeIncrement ( ref Statistics . _prepares ) ;
693
+ }
694
+ _hiddenPrepare = false ;
692
695
}
693
- _hiddenPrepare = false ;
694
- }
695
- else
696
- {
697
- // Validate the command outside of the try\catch to avoid putting the _stateObj on error
698
- ValidateCommand ( isAsync : false ) ;
699
-
700
- bool processFinallyBlock = true ;
701
- try
696
+ else
702
697
{
703
- // NOTE: The state object isn't actually needed for this, but it is still here for back-compat (since it does a bunch of checks)
704
- GetStateObject ( ) ;
698
+ // Validate the command outside of the try\catch to avoid putting the _stateObj on error
699
+ ValidateCommand ( isAsync : false ) ;
705
700
706
- // Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
707
- if ( null != _parameters )
701
+ bool processFinallyBlock = true ;
702
+ try
708
703
{
709
- int count = _parameters . Count ;
710
- for ( int i = 0 ; i < count ; ++ i )
704
+ // NOTE: The state object isn't actually needed for this, but it is still here for back-compat (since it does a bunch of checks)
705
+ GetStateObject ( ) ;
706
+
707
+ // Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
708
+ if ( null != _parameters )
711
709
{
712
- _parameters [ i ] . Prepare ( this ) ;
710
+ int count = _parameters . Count ;
711
+ for ( int i = 0 ; i < count ; ++ i )
712
+ {
713
+ _parameters [ i ] . Prepare ( this ) ;
714
+ }
713
715
}
714
- }
715
716
716
- InternalPrepare ( ) ;
717
- }
718
- catch ( Exception e )
719
- {
720
- processFinallyBlock = ADP . IsCatchableExceptionType ( e ) ;
721
- throw ;
722
- }
723
- finally
724
- {
725
- if ( processFinallyBlock )
717
+ InternalPrepare ( ) ;
718
+ }
719
+ catch ( Exception e )
720
+ {
721
+ processFinallyBlock = ADP . IsCatchableExceptionType ( e ) ;
722
+ throw ;
723
+ }
724
+ finally
726
725
{
727
- _hiddenPrepare = false ; // The command is now officially prepared
726
+ if ( processFinallyBlock )
727
+ {
728
+ _hiddenPrepare = false ; // The command is now officially prepared
728
729
729
- ReliablePutStateObject ( ) ;
730
+ ReliablePutStateObject ( ) ;
731
+ }
730
732
}
731
733
}
732
734
}
733
-
734
- SqlStatistics . StopTimer ( statistics ) ;
735
+ finally
736
+ {
737
+ SqlStatistics . StopTimer ( statistics ) ;
738
+ }
735
739
}
736
740
737
741
private void InternalPrepare ( )
0 commit comments