Along with logging the SqlException, I'm also trying to call another DB which is storing the content from where the error initially occured. However, I'm getting the warning 'Unreachable code detected' for the SqlConnection part and it definitely isn't executing the Procedure that I'm attempting to run.
catch (SqlException ex)
{
throw new DataException(ex.Message, ex);
//Call Error Management DB Connection and add content to the table
using (SqlConnection connection = new SqlConnection(_errorManagementConnectionString))
{
SqlCommand cmd = new SqlCommand("[dbo].[InsertDataErrors]", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@InputParam", InputParam);
cmd.Parameters.AddWithValue("@Content", Content);
cmd.ExecuteNonQuery();
connection.Open();
}
}
How can I tackle this error and ensure that the SqlException is logged along with the procedure that I'm trying to run?