示例#1
0
文件: DbHelper.cs 项目: ridgew/fmq
        /// <summary>
        /// 打开数据库连接
        /// </summary>
        private void ensureDbOpen()
        {
            try
            {
                bool blnOpend = false;
                if (conn == null)
                {
                    conn = new OleDbConnection(this.strConn);
                    conn.Open();
                    blnOpend = true;

                    //Util.Log2File("~/debug.log", "为空状态,打开数据库连接时间:"
                    //    + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")
                    //    + Environment.NewLine);
                }
                else
                {
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.ConnectionString = this.strConn;
                        conn.Open();
                        blnOpend = true;

                        //Util.Log2File("~/debug.log", "关闭状态,打开数据库连接时间:"
                        //    + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")
                        //    + Environment.NewLine);
                    }
                }

                //Util.Log2File("~/debug.log", "数据库状态" + conn.State + Environment.NewLine);

                if (blnOpend == true)
                {
                    //添加打开数据库次数
                    FanmaquerOleDbModule.AddProcessCount <int>("OleDbOpen", 1, new FanmaquerOleDbModule.OperatorData <int>(delegate(int count)
                    {
                        return(count + 1);
                    }));
                }

                //确保打开数据库次数,操作数
                FanmaquerOleDbModule.AddProcessCount <int>("OleExecCount", 1, new FanmaquerOleDbModule.OperatorData <int>(delegate(int count)
                {
                    return(count + 1);
                }));
            }
            catch (Exception e)
            {
                this.message = e.Message;
            }
        }
示例#2
0
文件: DbHelper.cs 项目: ridgew/fmq
        /// <summary>
        /// 释放连接对象
        /// </summary>
        public void Release()
        {
            if (conn != null && conn.State == ConnectionState.Open)
            {
                conn.Close();
                conn.Dispose();

                //Util.Log2File("~/debug.log", "销毁数据库时间:" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")
                //    + Environment.NewLine);

                //添加关闭销毁数据库连接对象次数
                FanmaquerOleDbModule.AddProcessCount <int>("OleDbClose", 1, new FanmaquerOleDbModule.OperatorData <int>(delegate(int count)
                {
                    return(count + 1);
                }));
            }
        }