In global.asax.vb
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
If TypeOf (Context.Error.GetBaseException) Is System.Data.SqlClient.SqlException Then
Dim ex As System.Data.SqlClient.SqlException = Context.Error.GetBaseException
If (ex.Errors.Count = 1 And ex.Number = -2) Then
Server.ClearError()
Response.Redirect(Context.Request.Url.ToString() & "?error=MessageHere")
End If
End If
End Sub
In C#
public void Application_Error(object sender, EventArgs e)
{
if ((Context.Error.GetBaseException) is System.Data.SqlClient.SqlException) {
System.Data.SqlClient.SqlException ex = Context.Error.GetBaseException;
if ((ex.Errors.Count == 1 & ex.Number == -2)) {
Server.ClearError();
Response.Redirect(Context.Request.Url.ToString() + "?error=MessageHere");
}
}
}