/// <summary> /// 关闭数据库连接 /// </summary> public void Close() { if (DbConn.State == ConnectionState.Open) { DbConn.Close(); } }
public void Dispose(bool isDispose) { if (TransStats == 1) { RollbackTrans(); } TransStats = 0; if (isDispose) { DbConn.Close(); DbConn.Dispose(); Command.Dispose(); DbConn = null; Command = null; } else { if (DbConn != null) { DbConnPool[Key].ReleaseObject(DbConn); } if (Command != null) { DbCommandPool.ReleaseObject(Command); } DbConn = null; Command = null; } }
/// <summary> /// 依SQL指令執行 /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public int ExecCmd(SqlCommand Cmd) { int RetV = 0; CheckDBConnection(); if (_bHasTrans) { Cmd.Connection = DbConn; Cmd.CommandTimeout = 30000; Cmd.Transaction = _trans; RetV = Cmd.ExecuteNonQuery(); } else { DbConn.Open(); Cmd.Connection = DbConn; Cmd.CommandTimeout = 30000; RetV = Cmd.ExecuteNonQuery(); DbConn.Close(); } return(RetV); }
public virtual ConnectionState CloseConn() { if (DbConn != null) { if (DbConn.State == ConnectionState.Open) { ErrorObject.Flag = Errors.Ok; try { DbConn.Close(); ConnectionStatus = ConnectionState.Closed; } catch (Exception ex) { DMEEditor.AddLogMessage("Fail", $"Could not close Connetion Database Function End {ex.Message}", DateTime.Now, 0, null, Errors.Failed); } return(DbConn.State); } else { ConnectionStatus = ConnectionState.Closed; return(ConnectionStatus); } } else { ConnectionStatus = ConnectionState.Closed; DMEEditor.AddLogMessage("Fail", $"Closing RDBMS Connection {ConnectionProp.ConnectionName}", DateTime.Now, 0, ConnectionProp.ConnectionName, Errors.Ok); return(ConnectionStatus); } }
public void CloseConnection() { if (DbConn != null && DbConn.State != ConnectionState.Closed) { DbConn.Close(); } }
public void CloseConnection() { if (dbConn != null) { dbConn.Close(); } }
/// <summary> /// 依SQL指令執行 /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public int ExecCmdAsync(string sSQL) { int RetV = 0; try { CheckDBConnection(); if (_bHasTrans) { System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn, _trans); IAsyncResult cres = Cmd.BeginExecuteNonQuery(null, null); RetV = Cmd.EndExecuteNonQuery(cres); } else { DbConn.Open(); System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn); //Cmd.CommandTimeout = 1500; //Cmd.EndExecuteNonQuery(); IAsyncResult cres = Cmd.BeginExecuteNonQuery(null, null); RetV = Cmd.EndExecuteNonQuery(cres); DbConn.Close(); } } catch (Exception ex) { string strMsg = "SQL指令執行失敗:" + sSQL + "\r\n" + ex.Message; throw new Exception(strMsg); } return(RetV); }
// 开始解析; private void parseFile_Click(object sender, RoutedEventArgs e) { List <Event> le = new List <Event>(); byte[] bytes = { 0x06, 0xD6, 0x12, 0x09, 0x00, 0x20, 0xFF, 0xFF, 0xFF, 0x28, 0xFF, 0xF0, 0x5A, 0xC4, 0x95, 0x6C, 0x1D, 0x36, 0xE3, 0xB4, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x5C, 0x00 }; IDbCommand sessionSqlCmd; DbOptions opts = new DbOptions(); opts.ConnStr = DbConnSqlite.GetConnectString(DbConnProvider.DefaultSqliteDatabaseName);; opts.ConnType = CDLBrowser.Parser.DatabaseMgr.DbType.SQLite; DbConn dbconn = new DbConn(opts); int ret = dbconn.CheckDatabaseTable(typeof(Event)); if (ret < 0) { return; } /* * dbconn.ExcuteNonQuery("PRAGMA synchronous = OFF"); * dbconn.ExcuteNonQuery("PRAGMA journal_mode = MEMORY"); */ sessionSqlCmd = dbconn.BeginTransaction(); string sql = string.Empty; EventParser parser = new EventParser(); parser.Version = "1.3.06659"; EventParserManager.Instance.AddEventParser(parser.Version, parser); Event newe = ParseEvent(bytes, "1.3.06659"); le.Add(newe); sql = dbconn.CreateInsertSqlFromObject(typeof(Event), newe, "Event", true); // dbconn.ExcuteByTrans(sql, sessionSqlCmd); IDbDataParameter dbparameterRaw = null; IDbDataParameter dbparameterBody = null; dbparameterRaw = new SQLiteParameter("@RawData", newe.RawData); dbparameterBody = new SQLiteParameter("@MsgBody", newe.MsgBody); IDbDataParameter[] paramsArray = new IDbDataParameter[2]; paramsArray[0] = dbparameterRaw; paramsArray[1] = dbparameterBody; dbconn.ExecuteWithParamtersByTrans(sql, paramsArray, sessionSqlCmd); dbconn.CommitChanges(sessionSqlCmd); dbconn.Close(); }
/// <summary> /// 依SQL指令取得資料結果(一個字串) /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public String GetSQLCmd_Str(string sSQL) { string sRetV = ""; CheckDBConnection(); if (_bHasTrans) { System.Data.SqlClient.SqlCommand Cmd1 = new System.Data.SqlClient.SqlCommand(); Cmd1.CommandTimeout = 30000; Cmd1.Connection = DbConn; Cmd1.Transaction = _trans; Cmd1.CommandText = sSQL; try { sRetV = Cmd1.ExecuteScalar() + ""; } catch (Exception ex) { _trans.Rollback(); throw new Exception("SQL指令執行失敗:" + sSQL + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } else { System.Data.SqlClient.SqlCommand Cmd1 = new System.Data.SqlClient.SqlCommand(); Cmd1.CommandTimeout = 30000; Cmd1.Connection = DbConn; Cmd1.CommandText = sSQL; DbConn.Open(); try { sRetV = Cmd1.ExecuteScalar() + ""; } catch (Exception ex) { DbConn.Close(); throw new Exception("SQL指令執行失敗:" + sSQL + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } DbConn.Close(); } return(sRetV); }
/// <summary> /// 依SQL指令執行 /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public int ExecCmd(string sSQL) { int RetV = 0; try { CheckDBConnection(); if (_bHasTrans) { System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn, _trans); Cmd.CommandTimeout = 30000; RetV = Cmd.ExecuteNonQuery(); } else { DbConn.Open(); System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn); Cmd.CommandTimeout = 30000; RetV = Cmd.ExecuteNonQuery(); DbConn.Close(); } } catch (Exception ex) { string strMsg = "SQL指令執行失敗:" + sSQL + "\r\n" + ex.Message + "\r\n" + ex.StackTrace; if (_bHasTrans) { try { _trans.Rollback(); } catch (Exception ex2) { strMsg += string.Format(" Rollback Exception Type: {0} ", ex2.GetType()); strMsg += string.Format(" StackTrace : {0} ", ex2.StackTrace); } } DbConn.Close(); throw new Exception(strMsg); } return(RetV); }
/// <summary> /// 依SQL指令執行(回傳自動編碼) /// </summary> /// <param name="sSQL"></param> /// <returns></returns> public int ExecCmd(SqlCommand Cmd, out int sNO) { sNO = 0; int RetV = 0; try { CheckDBConnection(); if (_bHasTrans) { Cmd.Connection = DbConn; Cmd.CommandTimeout = 30000; Cmd.Transaction = _trans; Cmd.CommandText += ";SELECT CAST(scope_identity() AS int)"; sNO = (Int32)Cmd.ExecuteScalar(); } else { DbConn.Open(); Cmd.Connection = DbConn; Cmd.CommandTimeout = 30000; Cmd.CommandText += ";SELECT CAST(scope_identity() AS int)"; sNO = (Int32)Cmd.ExecuteScalar(); } } catch { } finally { if (_bHasTrans) { } else { DbConn.Close(); } } return(RetV); }
public static void CloseConn() { DbConn.Close(); }
public void CompatibilityTestTearDown() { DbConn.Close(); }
/// <summary> /// 依SQL指令執行(回傳自動編碼) /// </summary> /// <param name="sSQL"></param> /// <param name="sNO"></param> /// <returns></returns> public void ExecCmd(string sSQL, out int sNO) { sNO = 0; try { CheckDBConnection(); if (_bHasTrans) { System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn, _trans); Cmd.CommandTimeout = 30000; if (Cmd.ExecuteNonQuery() == 1) { Cmd = new System.Data.SqlClient.SqlCommand(); Cmd.CommandText = "Select SCOPE_IDENTITY()"; Cmd.Connection = DbConn; Cmd.Transaction = _trans; System.Data.SqlClient.SqlDataReader dr = Cmd.ExecuteReader(); if (dr.Read()) { sNO = Convert.ToInt32(dr.GetValue(0)); } dr.Close(); } } else { DbConn.Open(); System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand(sSQL, DbConn); Cmd.CommandTimeout = 30000; if (Cmd.ExecuteNonQuery() == 1) { DbConn.Close(); DbConn.Open(); Cmd = new System.Data.SqlClient.SqlCommand(); Cmd.CommandText = "Select SCOPE_IDENTITY()"; Cmd.Connection = DbConn; System.Data.SqlClient.SqlDataReader dr = Cmd.ExecuteReader(); if (dr.Read()) { sNO = Convert.ToInt32(dr.GetValue(0)); } dr.Close(); } } } catch { } finally { if (_bHasTrans) { } else { DbConn.Close(); } } }