Skip to content

Commit

Permalink
Catch exceptions in CanConnect and return false
Browse files Browse the repository at this point in the history
Fixes #18355
  • Loading branch information
roji committed Nov 14, 2019
1 parent 5862d23 commit 288fedb
Showing 1 changed file with 22 additions and 3 deletions.
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;
}
}
}
}

0 comments on commit 288fedb

Please sign in to comment.