@@ -61,7 +61,7 @@ public override void AddToBatch(IExpectation expectation)
61
61
{
62
62
Log . Debug ( "Adding to batch:" + lineWithParameters ) ;
63
63
}
64
- _currentBatch . Append ( ( System . Data . SqlClient . SqlCommand ) batchUpdate ) ;
64
+ _currentBatch . Append ( ( System . Data . SqlClient . SqlCommand ) batchUpdate ) ;
65
65
66
66
if ( _currentBatch . CountOfCommands >= _batchSize )
67
67
{
@@ -71,27 +71,31 @@ public override void AddToBatch(IExpectation expectation)
71
71
72
72
protected override void DoExecuteBatch ( DbCommand ps )
73
73
{
74
- Log . DebugFormat ( "Executing batch" ) ;
75
- CheckReaders ( ) ;
76
- Prepare ( _currentBatch . BatchCommand ) ;
77
- if ( Factory . Settings . SqlStatementLogger . IsDebugEnabled )
78
- {
79
- Factory . Settings . SqlStatementLogger . LogBatchCommand ( _currentBatchCommandsLog . ToString ( ) ) ;
80
- }
81
-
82
- int rowsAffected ;
83
74
try
84
75
{
85
- rowsAffected = _currentBatch . ExecuteNonQuery ( ) ;
76
+ Log . DebugFormat ( "Executing batch" ) ;
77
+ CheckReaders ( ) ;
78
+ Prepare ( _currentBatch . BatchCommand ) ;
79
+ if ( Factory . Settings . SqlStatementLogger . IsDebugEnabled )
80
+ {
81
+ Factory . Settings . SqlStatementLogger . LogBatchCommand ( _currentBatchCommandsLog . ToString ( ) ) ;
82
+ }
83
+ int rowsAffected ;
84
+ try
85
+ {
86
+ rowsAffected = _currentBatch . ExecuteNonQuery ( ) ;
87
+ }
88
+ catch ( DbException e )
89
+ {
90
+ throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , e , "could not execute batch command." ) ;
91
+ }
92
+
93
+ Expectations . VerifyOutcomeBatched ( _totalExpectedRowsAffected , rowsAffected ) ;
86
94
}
87
- catch ( DbException e )
95
+ finally
88
96
{
89
- throw ADOExceptionHelper . Convert ( Factory . SQLExceptionConverter , e , "could not execute batch command." ) ;
97
+ ClearCurrentBatch ( ) ;
90
98
}
91
-
92
- Expectations . VerifyOutcomeBatched ( _totalExpectedRowsAffected , rowsAffected ) ;
93
-
94
- ClearCurrentBatch ( ) ;
95
99
}
96
100
97
101
private SqlClientSqlCommandSet CreateConfiguredBatch ( )
0 commit comments