File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
src/EFCore.Relational/Storage Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -373,7 +373,8 @@ public virtual bool CanConnect()
373373 /// </summary>
374374 /// <remarks>
375375 /// <para>
376- /// Any exceptions thrown when attempting to connect are caught and not propagated to the application.
376+ /// Any exceptions thrown when attempting to connect are caught and not propagated to the application,
377+ /// except for the ones indicating cancellation.
377378 /// </para>
378379 /// <para>
379380 /// The configured connection string is used to create the connection in the normal way, so all
@@ -386,13 +387,16 @@ public virtual bool CanConnect()
386387 /// </remarks>
387388 /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
388389 /// <returns><see langword="true" /> if the database is available; <see langword="false" /> otherwise.</returns>
389- /// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
390390 public virtual async Task < bool > CanConnectAsync ( CancellationToken cancellationToken = default )
391391 {
392392 try
393393 {
394394 return await ExistsAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
395395 }
396+ catch ( Exception exception ) when ( Dependencies . ExceptionDetector . IsCancellation ( exception , cancellationToken ) )
397+ {
398+ throw ;
399+ }
396400 catch
397401 {
398402 return false ;
Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ public RelationalDatabaseCreatorDependencies(
5454 IExecutionStrategy executionStrategy ,
5555 ICurrentDbContext currentContext ,
5656 IDbContextOptions contextOptions ,
57- IRelationalCommandDiagnosticsLogger commandLogger )
57+ IRelationalCommandDiagnosticsLogger commandLogger ,
58+ IExceptionDetector exceptionDetector )
5859 {
5960 Connection = connection ;
6061 ModelDiffer = modelDiffer ;
@@ -65,6 +66,7 @@ public RelationalDatabaseCreatorDependencies(
6566 CurrentContext = currentContext ;
6667 ContextOptions = contextOptions ;
6768 CommandLogger = commandLogger ;
69+ ExceptionDetector = exceptionDetector ;
6870 }
6971
7072 /// <summary>
@@ -111,4 +113,9 @@ public RelationalDatabaseCreatorDependencies(
111113 /// Contains the <see cref="DbContext" /> currently in use.
112114 /// </summary>
113115 public ICurrentDbContext CurrentContext { get ; init ; }
116+
117+ /// <summary>
118+ /// Gets the exception detector.
119+ /// </summary>
120+ public IExceptionDetector ExceptionDetector { get ; init ; }
114121}
You can’t perform that action at this time.
0 commit comments