Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ public virtual bool CanConnect()
/// </summary>
/// <remarks>
/// <para>
/// Any exceptions thrown when attempting to connect are caught and not propagated to the application.
/// Any exceptions thrown when attempting to connect are caught and not propagated to the application,
/// except for the ones indicating cancellation.
/// </para>
/// <para>
/// The configured connection string is used to create the connection in the normal way, so all
Expand All @@ -386,13 +387,16 @@ public virtual bool CanConnect()
/// </remarks>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns><see langword="true" /> if the database is available; <see langword="false" /> otherwise.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
public virtual async Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
{
try
{
return await ExistsAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception exception) when (Dependencies.ExceptionDetector.IsCancellation(exception, cancellationToken))
{
throw;
}
catch
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public RelationalDatabaseCreatorDependencies(
IExecutionStrategy executionStrategy,
ICurrentDbContext currentContext,
IDbContextOptions contextOptions,
IRelationalCommandDiagnosticsLogger commandLogger)
IRelationalCommandDiagnosticsLogger commandLogger,
IExceptionDetector exceptionDetector)
{
Connection = connection;
ModelDiffer = modelDiffer;
Expand All @@ -65,6 +66,7 @@ public RelationalDatabaseCreatorDependencies(
CurrentContext = currentContext;
ContextOptions = contextOptions;
CommandLogger = commandLogger;
ExceptionDetector = exceptionDetector;
}

/// <summary>
Expand Down Expand Up @@ -111,4 +113,9 @@ public RelationalDatabaseCreatorDependencies(
/// Contains the <see cref="DbContext" /> currently in use.
/// </summary>
public ICurrentDbContext CurrentContext { get; init; }

/// <summary>
/// Gets the exception detector.
/// </summary>
public IExceptionDetector ExceptionDetector { get; init; }
}