I am unable to catch the logon SqlException
in C#.
This is my code:
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
}
catch (SqlException)
{ }
}
It is not even working like this:
catch (Exception) { }
This should catch ALL exceptions, but it does not. The SqlExceptions
always gets thrown. This is what it says:
SqlException:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dllAdditional information: Cannot open database "foo" requested by the login. The login failed.
I am using the exact same try/catch when reading from the database (to catch a TimeOut) and it works perfectly fine. Also tried some variants from this question, but no luck so far.
Specs: Visual Studio 2013 Prem v12.0, .NET 4.5, Win8.1