/// <summary> /// See interface docs. /// </summary> /// <param name="ex"></param> public void Initialise(Exception ex) { #if DOTNET_BUILD _Exception = ex as System.Data.SQLite.SQLiteException; #else _Exception = ex as Mono.Data.Sqlite.SqliteException; #endif }
/// <summary> /// Handle DB specific exceptions. /// Write errors to console only. /// </summary> /// <param name="dbx">the exception</param> /// <param name="sql">the SQL statement text that threw the error</param> /// <returns>return true if exception is from the preferred provider and no database was found, so that caller may try to create a new database</returns> public static bool DBExceptionHandler(DbException dbx, string sql) { bool neednew = false; //if (dbx is System.Data.SqlServerCe.SqlCeException) // SQL Server CE -- specific test against various SQL errors v. the no database found error //{ // System.Data.SqlServerCe.SqlCeException x = (System.Data.SqlServerCe.SqlCeException)dbx; // //x.NativeError == // DBMain.AltLog(LogLevels.Warning, 70147, DBExceptionString(dbx, sql)); //} //else if (dbx is System.Data.SQLite.SQLiteException) // SQLite3 -- specific test against various SQL errors v. the no database found error { System.Data.SQLite.SQLiteException x = (System.Data.SQLite.SQLiteException)dbx; if (x.ResultCode == SQLiteErrorCode.Error) // SQL error or missing database { neednew = !(dbx.Message.EndsWith("syntax error") || // not an SQL syntax error dbx.Message.Contains("no such table") || //or malformed schema, dbx.Message.Contains("has no column named")); // nor mismatched column, but likely a missing DB if (!neednew) { DBMain.AltLog(LogLevels.Warning, 70136, DBExceptionString(dbx, sql), true); } } else { DBMain.AltLog(LogLevels.Warning, 70137, DBExceptionString(dbx, sql)); } } else if (dbx is System.Data.OleDb.OleDbException) // Access { DBMain.AltLog(LogLevels.Warning, 70140, DBExceptionString(dbx, sql)); // todo: expand when the "no DB present" code is known } else if (dbx is System.Data.Common.DbException) // anything else { DBMain.AltLog(LogLevels.Warning, 70139, DBExceptionString(dbx, sql)); // todo: expand when the "no DB present" code is known } else { Console.WriteLine(DBExceptionString(dbx, sql)); } return(neednew); }
public static tgConcurrencyException CheckForConcurrencyException(SQLiteException ex) { tgConcurrencyException ce = null; return ce; }
// // WriteToEventLog // A helper Function that writes exception detail to the event log. Exceptions // are written to the event log as a security measure to avoid private database // details from being returned to the browser. If a method does not return a status // or boolean indicating the action succeeded or failed, a generic exception is also // thrown by the caller. // private void WriteToEventLog(SQLiteException e, string action) { EventLog log = new EventLog(); log.Source = eventSource; log.Log = eventLog; string message = exceptionMessage + "\\n\\n"; message += "Action: " + action + "\\n\\n"; message += "Exception: " + e.ToString(); log.WriteEntry(message); }
private void Crash(SQLiteException s, bool logerror) { if(logerror) throw new CDatabaseException(string.Format(sLConsole.SQLite("Text2"), s.Message)); }
private void Crash(SQLiteException s, bool logerror, bool c = false) { if(c) { _crash = true; Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message); Log.Warning("SQLite", sLConsole.GetString("Program shutting down!")); SchumixBase.Quit(false); foreach(var nw in INetwork.WriterList) { if(!nw.Value.IsNull()) nw.Value.WriteLine("QUIT :Sql connection crash."); } Thread.Sleep(1000); sRuntime.Exit(); } if(s.Message.Contains("Fatal error encountered during command execution.")) { _crash = true; Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message); Log.Warning("SQLite", sLConsole.GetString("Program shutting down!")); SchumixBase.Quit(false); foreach(var nw in INetwork.WriterList) { if(!nw.Value.IsNull()) nw.Value.WriteLine("QUIT :Sql connection crash."); } Thread.Sleep(1000); sRuntime.Exit(); } if(s.Message.Contains("Timeout expired.")) { _crash = true; Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message); Log.Warning("SQLite", sLConsole.GetString("Program shutting down!")); SchumixBase.Quit(false); foreach(var nw in INetwork.WriterList) { if(!nw.Value.IsNull()) nw.Value.WriteLine("QUIT :Sql connection timeout."); } Thread.Sleep(1000); sRuntime.Exit(); } if(logerror) Log.Error("SQLite", sLConsole.GetString("Query error: {0}"), s.Message); }
/// <summary> /// Handle Non Fatal SQL Query Exception /// </summary> /// <param name="sqle">SQL Excepiton</param> /// <returns>True if handled, False otherwise</returns> protected static bool HandleSQLException(SQLiteException sqle) { switch (sqle.ResultCode) { case SQLiteErrorCode.Constraint: case SQLiteErrorCode.Constraint_Check: case SQLiteErrorCode.Constraint_ForeignKey: case SQLiteErrorCode.Constraint_Unique: case SQLiteErrorCode.Constraint_NotNull: return true; default: return false; } }