Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exceptions in CanConnect and return false #18867

Merged
merged 1 commit into from
Nov 14, 2019
Merged
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
25 changes: 22 additions & 3 deletions src/EFCore.Relational/Storage/RelationalDatabaseCreator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -314,7 +315,16 @@ public virtual string GenerateCreateScript()
/// </summary>
/// <returns> <c>True</c> if the database is available; <c>false</c> otherwise. </returns>
public virtual bool CanConnect()
=> Exists();
{
try
{
return Exists();
}
catch
{
return false;
}
}

/// <summary>
/// <para>
Expand All @@ -327,7 +337,16 @@ public virtual bool CanConnect()
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns> <c>True</c> if the database is available; <c>false</c> otherwise. </returns>
public virtual Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
=> ExistsAsync(cancellationToken);
public virtual async Task<bool> CanConnectAsync(CancellationToken cancellationToken = default)
{
try
{
return await ExistsAsync(cancellationToken);
}
catch
{
return false;
}
}
}
}