Ejemplo n.º 1
0
        /// <summary>
        /// close database with connectstring
        /// </summary>
        public void Close()
        {
            if (conn == null)
            {
                throw new Exception("Connection has not initialize.");
            }

            if (conn.IsValid() == false)
            {
                throw new Exception("Connection is already closed.");
            }

            conn.Close();
            conn.Dispose();
            conn = null;
        }
Ejemplo n.º 2
0
        public void BackConnection(PDBConnection conn, bool isErr)
        {
            if (!isErr && conn.IsValid())
            {
                lock (this)
                {
                    connList_.Add(conn);
                }
            }
            else
            {
                conn.Dispose();
                Interlocked.Decrement(ref curConnCnt_);
            }

            connEvent_.Set();
        }
Ejemplo n.º 3
0
        public PDBConnection GetConnection()
        {
            do
            {
                lock (this)
                {
                    while (connList_.Count > 0)
                    {
                        int           idx     = connList_.Count - 1;
                        PDBConnection tmpConn = connList_[idx];
                        connList_.RemoveAt(idx);

                        if (tmpConn.IsValid())
                        {
                            return(tmpConn);
                        }
                        else
                        {
                            tmpConn.Dispose();
                            Interlocked.Decrement(ref curConnCnt_);
                            connEvent_.Set();
                        }
                    }

                    if (curConnCnt_ < maxConnCnt_)
                    {
                        PDBConnection conn = new PDBConnection(connStr_);
                        conn.Open();
                        Interlocked.Increment(ref curConnCnt_);
                        return(conn);
                    }
                    else
                    {
                        connEvent_.Reset();
                    }
                }

                connEvent_.WaitOne();
            } while (true);
        }