asp.net 資料庫訪問組件支援Using

來源:互聯網
上載者:User

調用代碼

        private void testusing()
        {
            using (idbhelper dbhelper = new sqlhelper(basesysteminfo.usercenterdbconnection))
            {
                dbhelper.executenonquery(" select getdate() ");
            }
        }

原始碼。

//------------------------------------------------------------
// all rights reserved , copyright (c) 2010 , jirisoft , ltd.
//------------------------------------------------------------

using system;
using system.data;
using system.data.common;
using system.io;
using system.text;

namespace dotnet.dbutilities
{
    using dotnet.utilities;

    /// <summary>
    /// basedbhelper
    /// 有關資料庫教程串連的方法。
    ///
    /// 修改紀錄
    ///
    ///        2011.01.29 版本:3.1 jirigala 實現idisposable介面。
    ///        2010.06.13 版本:3.0 jirigala 改進為支援靜態方法,不用資料庫open、close的方式,autoopenclose開關。
    ///        2010.03.14 版本:2.0 jirigala 無法徹底釋放、並發時出現異常問題解決。
    ///        2009.11.25 版本:1.0 jirigala 改進connectionstring。
    ///
    /// 版本:3.1
    ///
    /// <author>
    ///        <name>jirigala</name>
    ///        <date>2011.01.29</date>
    /// </author>
    /// </summary>
    public abstract class basedbhelper : idisposable // idbhelper
    {

        代碼省略

        public void dispose()
        {
            this.dbcommand = null;
            this.dbdataadapter = null;
            this.dbtransaction = null;
            // 關閉資料庫連接
            if (this.dbconnection != null)
            {
                if (this.dbconnection.state != connectionstate.closed)
                {
                    this.dbconnection.close();
                }
            }
            this.dbconnection = null;
        }
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.