/// <summary> /// Generate a detailed report for an ingres exception. /// </summary> /// <param name="ex">The exception to generate a report for.</param> /// <param name="message">A custom message to include in the report.</param> /// <returns>A detailed exception report.</returns> public static string ExceptionDetailReport(IngresException ex, string message) { StringBuilder sb = new StringBuilder(); sb.AppendLine("*****************************************************************************"); sb.AppendLine(String.Format("Ingres Exception Detail Dump - Generated {0}", DateTime.Now)); sb.AppendLine("*****************************************************************************\n"); sb.AppendLine(message + "\n\n"); sb.AppendLine(string.Format("Source : {0}\n", ex.Source)); sb.AppendLine(string.Format("Message : {0}\n", ex.Message)); sb.AppendLine(string.Format("Help Link : {0}\n", ex.HelpLink)); sb.AppendLine(string.Format("Stack Trace : {0}\n\n", ex.StackTrace)); IngresErrorCollection errorCollection = ex.Errors; foreach (IngresError ingresError in errorCollection) { sb.Append(Environment.NewLine); sb.AppendLine(String.Format("Message : {0}", ingresError.Message)); sb.AppendLine(String.Format("Native Error : {0}", ingresError.NativeError)); sb.AppendLine(String.Format("Number : {0}", ingresError.Number)); sb.AppendLine(String.Format("Source : {0}", ingresError.Source)); sb.AppendLine(String.Format("SQL State : {0}", ingresError.SQLState)); } return sb.ToString(); }
/// <summary> /// Generate a detailed report for an ingres exception. /// </summary> /// <param name="ex">The exception to generate a report for.</param> /// <param name="message">A custom message to include in the report.</param> /// <returns>A detailed exception report.</returns> public static string ExceptionDetailReport(IngresException ex, string message) { StringBuilder sb = new StringBuilder(); sb.AppendLine("*****************************************************************************"); sb.AppendLine(String.Format("Ingres Exception Detail Dump - Generated {0}", DateTime.Now)); sb.AppendLine("*****************************************************************************\n"); sb.AppendLine(message + "\n\n"); sb.AppendLine(string.Format("Source : {0}\n", ex.Source)); sb.AppendLine(string.Format("Message : {0}\n", ex.Message)); sb.AppendLine(string.Format("Help Link : {0}\n", ex.HelpLink)); sb.AppendLine(string.Format("Stack Trace : {0}\n\n", ex.StackTrace)); IngresErrorCollection errorCollection = ex.Errors; foreach (IngresError ingresError in errorCollection) { sb.Append(Environment.NewLine); sb.AppendLine(String.Format("Message : {0}", ingresError.Message)); sb.AppendLine(String.Format("Native Error : {0}", ingresError.NativeError)); sb.AppendLine(String.Format("Number : {0}", ingresError.Number)); sb.AppendLine(String.Format("Source : {0}", ingresError.Source)); sb.AppendLine(String.Format("SQL State : {0}", ingresError.SQLState)); } return(sb.ToString()); }
/// <summary> /// Manages error handling when we encounter an IngresException. If we are debugging we /// simply rethro the exception - otherwise log the error and throw a "friendly" error to /// the user. /// </summary> /// <param name="ex">The Ingres exception to handle.</param> /// <param name="provider">The Ingres ASP.NET provider that caused the exception to be thrown.</param> /// <param name="detail">The detail of the exception.</param> private static void HandleIngresException(IngresException ex, IngresAspNetProvider provider, string detail) { #if DEBUG // The debugging constant is automatically handled by Visual Studio for us // When we are debugging we want to actually throw the errors rather than just writing the // details to the event log and throwing a generic provider error. throw ex; #else // This code becomes reachable when we are not in debug mode LogError(ExceptionDetailReport(ex, detail), provider); throw new ProviderException(Messages.IngresExceptionErrorMessage); #endif }
// Name: DisplayError // // Description: // Function to show the properties of IngresException and // IngresError classes. // Extracts exception and error text and forms a dialog string. // Provides an example of handling SQLstate errors. // // Input: // ex IngresException class. // // Output: // None. // // Returns: // Depends on the buttons enabled for the dialog. // DialogResult.OK // DialogResult.Cancel // // History: // 02-Oct-2006 ([email protected]) // Created. // 02-Feb-2006 ([email protected]) // Add user message string for connection failure. public DialogResult DisplayError(IngresException ex) { String userText = ""; String ingError = ""; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon = MessageBoxIcon.Information; Int32 unwindLevel = 5; // Set the level to scan through errors // Adjust this value to include the // collection of errors in the display. Int32 nested = 0; ingError += ex.GetType().ToString() + "\n\nException Properties\n"; // IngresException Class properties: // // InnerException The nested Exception instance that caused the // current exception. Inherited from Exception. // Message A concatenation of all the messages in the // Errors collection. // Source Name of the data provider that generated the // error. Always "Ingres." // StackTrace A string representation of the frames on the // call stack at the time the current exception // was thrown. // TargetSite The method that threw the current exception. // Inherited from Exception. // // For property descriptions of the IngresException class see // the IngresException Class Properties section in the Ingres // Connectivity Guide if (ex.HelpLink != null) { ingError += "HelpLink: " + ex.HelpLink.ToString() + "\n"; } if (ex.InnerException != null) { ingError += "Inner Exception: " + ex.InnerException.ToString() + "\n"; } if (ex.Message != null) { ingError += "Message: " + ex.Message.ToString() + "\n"; } if (ex.Source != null) { ingError += "Source: " + ex.Source.ToString() + "\n"; } if (ex.TargetSite != null) { ingError += "Target Site: " + ex.TargetSite.ToString() + "\n"; } ingError += "\nErrors\n"; foreach (IngresError e in ex.Errors) { // Don't processes any errors beyond the unwindLevel if (nested == unwindLevel) continue; // IngresError Class properties: // // Message A description of the error. // Number The database-specific error integer information // returned by the Ingres database. // Source Name of the data provider that generated the // error. Always "Ingres." // SQLState The standard five-character SQLSTATE code. // // For property descriptions of the IngresError class see // the IngresError Class Properties section in the Ingres // Connectivity Guide switch (e.SQLState) { case "00000": case "01000": break; case "02000": icon = MessageBoxIcon.Warning; break; case "08001": if (nested == 0) { userText += rm.GetString("SQLSTATE" + e.SQLState); } button = MessageBoxButtons.OKCancel; icon = MessageBoxIcon.Error; break; default: button = MessageBoxButtons.OKCancel; icon = MessageBoxIcon.Error; break; } ingError += String.Format("SQLState: " + e.SQLState.ToString() + " " + e.Message + "\n"); if (e.NativeError != 0) { ingError += String.Format("Ingres Error code: 0x{0:x08}\n", e.Number); } nested += 1; } if (userText.Length > 0) { ingError += "\n"; ingError += userText; } DialogResult result = MessageBox.Show(ingError, rm.GetString("Display"), button, icon); return (result); }