@@ -671,67 +671,71 @@ override public void Prepare()
671671 // between entry into Execute* API and the thread obtaining the stateObject.
672672 _pendingCancel = false ;
673673
674-
675674 SqlStatistics statistics = null ;
676- statistics = SqlStatistics . StartTimer ( Statistics ) ;
675+ try
676+ {
677+ statistics = SqlStatistics . StartTimer ( Statistics ) ;
677678
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+ )
686687
687- )
688- {
689- if ( null != Statistics )
688+ )
690689 {
691- Statistics . SafeIncrement ( ref Statistics . _prepares ) ;
690+ if ( null != Statistics )
691+ {
692+ Statistics . SafeIncrement ( ref Statistics . _prepares ) ;
693+ }
694+ _hiddenPrepare = false ;
692695 }
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
702697 {
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 ) ;
705700
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
708703 {
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 )
711709 {
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+ }
713715 }
714- }
715716
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
726725 {
727- _hiddenPrepare = false ; // The command is now officially prepared
726+ if ( processFinallyBlock )
727+ {
728+ _hiddenPrepare = false ; // The command is now officially prepared
728729
729- ReliablePutStateObject ( ) ;
730+ ReliablePutStateObject ( ) ;
731+ }
730732 }
731733 }
732734 }
733-
734- SqlStatistics . StopTimer ( statistics ) ;
735+ finally
736+ {
737+ SqlStatistics . StopTimer ( statistics ) ;
738+ }
735739 }
736740
737741 private void InternalPrepare ( )
0 commit comments