Additional SQL Server features and topics not covered by specific categories
You could do a brute force connect with a time-out.
Setup a CancellationTokenSource, here to time-out in two seconds
private static int _timeOut = 2;
private CancellationTokenSource _cancellationTokenSource =
new CancellationTokenSource(TimeSpan.FromSeconds(_timeOut));
Method to test connection
public class Operations
{
public static async Task<(bool success, Exception exception)> Connect(string connectionString, CancellationToken cancellationToken)
{
try
{
await using var cn = new SqlConnection(connectionString);
await cn.OpenAsync(cancellationToken);
return (true, null);
}
catch (Exception e)
{
return (false, e);
}
}
}
Call it and deconstruct the results
var (success, exception) = await Operations.Connect("user connection string goes here",_cancellationTokenSource.Token);
Side note, there is always a permission issue, connection string may be good but not assessible to the user.