protected void Application_Error(object sender, EventArgs e) { if (DataContextTransaction != null) { DataContextTransaction.Rollback(); DataContextTransaction.Dispose(); DataContextTransaction = null; } }
private static void CommitAndCloseDatabaseIfNecessary() { var dataContext = DataContextSimple; if (dataContext != null) { dataContext.SaveChanges(); if (DataContextTransaction != null) { DataContextTransaction.Commit(); DataContextTransaction.Dispose(); } dataContext.Dispose(); DataContextSimple = null; } }