@@ -194,7 +194,7 @@ private IList<T> MapToList<T>(DbDataReader dr)
194
194
/// <typeparam name="T"></typeparam>
195
195
/// <param name="command"></param>
196
196
/// <returns></returns>
197
- public static void ExecuteStoredProc ( this DbCommand command , Action < SprocResults > handleResults , System . Data . CommandBehavior commandBehaviour = System . Data . CommandBehavior . Default )
197
+ public static void ExecuteStoredProc ( this DbCommand command , Action < SprocResults > handleResults , System . Data . CommandBehavior commandBehaviour = System . Data . CommandBehavior . Default , bool manageConnection = true )
198
198
{
199
199
if ( handleResults == null )
200
200
{
@@ -203,7 +203,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
203
203
204
204
using ( command )
205
205
{
206
- if ( command . Connection . State == System . Data . ConnectionState . Closed )
206
+ if ( manageConnection && command . Connection . State == System . Data . ConnectionState . Closed )
207
207
command . Connection . Open ( ) ;
208
208
try
209
209
{
@@ -216,7 +216,10 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
216
216
}
217
217
finally
218
218
{
219
- command . Connection . Close ( ) ;
219
+ if ( manageConnection )
220
+ {
221
+ command . Connection . Close ( ) ;
222
+ }
220
223
}
221
224
}
222
225
}
@@ -227,7 +230,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
227
230
/// <typeparam name="T"></typeparam>
228
231
/// <param name="command"></param>
229
232
/// <returns></returns>
230
- public async static Task ExecuteStoredProcAsync ( this DbCommand command , Action < SprocResults > handleResults , System . Data . CommandBehavior commandBehaviour = System . Data . CommandBehavior . Default , CancellationToken ct = default ( CancellationToken ) )
233
+ public async static Task ExecuteStoredProcAsync ( this DbCommand command , Action < SprocResults > handleResults , System . Data . CommandBehavior commandBehaviour = System . Data . CommandBehavior . Default , CancellationToken ct = default ( CancellationToken ) , bool manageConnection = true )
231
234
{
232
235
if ( handleResults == null )
233
236
{
@@ -236,7 +239,7 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
236
239
237
240
using ( command )
238
241
{
239
- if ( command . Connection . State == System . Data . ConnectionState . Closed )
242
+ if ( manageConnection && command . Connection . State == System . Data . ConnectionState . Closed )
240
243
await command . Connection . OpenAsync ( ct ) . ConfigureAwait ( false ) ;
241
244
try
242
245
{
@@ -248,7 +251,10 @@ public static void ExecuteStoredProc(this DbCommand command, Action<SprocResults
248
251
}
249
252
finally
250
253
{
251
- command . Connection . Close ( ) ;
254
+ if ( manageConnection )
255
+ {
256
+ command . Connection . Close ( ) ;
257
+ }
252
258
}
253
259
}
254
260
}
0 commit comments