public virtual void Dispose() { Trans?.Dispose(); SqlConnection?.Dispose(); Trans = null; SqlConnection = null; }
public static Boolean UTSingleQuery(string updateSQL) { Boolean status = true; try { GC.Collect(); SqlTransaction Trans; SqlConnection conn = new SqlConnection(Login.connString); conn.Open(); Trans = conn.BeginTransaction(); try { SqlCommand cmd = new SqlCommand(updateSQL, conn, Trans); cmd.ExecuteNonQuery(); Trans.Commit(); Trans.Dispose(); conn.Close(); conn.Dispose(); } catch (Exception ex) { status = false; Trans.Rollback(); MessageBox.Show("UTSingleQuery() : Failed"); } } catch (Exception ex) { MessageBox.Show("UTSingleQuery() : Failed"); status = false; } return(status); }
/// <summary> /// Dispose the connection /// </summary> public virtual void Dispose() { OpenedDataReaders.Clear(); _attachedObjects.Clear(); Trans?.Dispose(); SqlConnection?.Dispose(); Trans = null; SqlConnection = null; }
public static Boolean UT(string QueryStrings) { Boolean status = true; try { string updateSQL; string[] queries = QueryStrings.Split(new string[] { Main.QueryDelimiter }, StringSplitOptions.None); if (queries.Length > 0) { SqlTransaction Trans; SqlConnection conn = new SqlConnection(Login.connString); conn.Open(); Trans = conn.BeginTransaction(); try { for (int i = 0; i < queries.Length; i++) { if (queries[i].Trim().Length > 0) { updateSQL = queries[i]; SqlCommand cmd = new SqlCommand(updateSQL, conn, Trans); cmd.ExecuteNonQuery(); } } Trans.Commit(); Trans.Dispose(); conn.Close(); conn.Dispose(); } catch (Exception ex) { status = false; Trans.Rollback(); MessageBox.Show("UT() : Failed"); } } } catch (Exception ex) { MessageBox.Show("UT() : Failed"); status = false; } return(status); }
/// <summary> /// commit the transaction /// </summary> public void SaveChanges() { try { Trans?.Commit(); } catch { Rollback(); throw; } finally { OpenedDataReaders.Clear(); Trans?.Dispose(); SqlConnection?.Dispose(); Trans = null; SqlConnection = null; } }
/// <summary> /// commit the transaction /// </summary> public void SaveChanges() { try { Trans?.Commit(); } catch (Exception ex) { Rollback(); throw new EntityException(ex.Message); } finally { OpenedDataReaders.Clear(); Trans?.Dispose(); SqlConnection?.Dispose(); Trans = null; SqlConnection = null; } }
/// <summary> /// 关闭 /// </summary> public void Close() { if (isClose) { return; } if (!isCommitOrRollback) { isCommitOrRollback = true; Trans.Rollback(); } if (Connection.State != ConnectionState.Closed) { Connection.Close(); } Trans.Dispose(); isClose = true; }