I want to catch specific SqlExceptions
in my code. Suppose If I want to check if the Exception is caused due to some connection failure then I want to send a message to the client DB Connectivity issue
. Is there a way I can check it programmatically?
public void GetData()
{
try
{
using (con)
{
....
con.Open();
cmd.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
//if(ex == sqlconnectionexception)
throw new FaultException(new FaultReason(new FaultReasonText("DB Connectivity issue")));
}
}