調用代碼
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;
}
}
}