我想在我的代码中捕获特定的SqlExceptions
。假设如果我想检查是否由于某些连接失败而导致异常,那么我想向客户端DB Connectivity issue
发送消息。有没有办法可以通过编程方式检查它?
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")));
}
}