首页 新闻 会员 周边 捐助

AccessHelper无法关闭数据库~

0
悬赏园豆:10 [已关闭问题]
<P>下面的accesshelper是我从SqlHelper改过来的,但是使用中发现调用某个方法后,数据库一直处于连接状态,这样再操作数据库就出错了。烦恼中,请各位大侠帮忙,看要怎么修改,方法调用结束后可以立刻关闭数据库。</P> <P>using System;<BR>using System.Data;<BR>using System.Configuration;<BR>using System.Web;<BR>using System.Web.Security;<BR>using System.Collections;<BR>using System.Data.OleDb;</P> <P>namespace Jdpc<BR>{<BR>&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<BR>&nbsp;&nbsp;&nbsp; /// 数据库的通用访问代码<BR>&nbsp;&nbsp;&nbsp; /// 此类为抽象类,不允许实例化,在应用时直接调用即可<BR>&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<BR>&nbsp;&nbsp;&nbsp; public abstract class AccessbHelper<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取数据库连接字符串,其属于静态变量且只读,项目中所有文档可以直接使用,但不能修改<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static readonly string ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 哈希表用来存储缓存的参数信息,哈希表可以存储任意类型的参数。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///执行一个不需要返回值的OleDbCommand命令,通过指定专用的连接字符串。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// 使用参数数组形式提供参数列表 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;remarks&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// 使用示例:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///&nbsp; int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new OleDbParameter("@prodid", 24));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/remarks&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="connectionString"&gt;一个有效的数据库连接字符串&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="commandType"&gt;OleDbCommand命令类型 (存储过程, T-OleDb语句, 等等。)&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="commandText"&gt;存储过程的名字或者 T-OleDb 语句&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="commandParameters"&gt;以数组形式提供OleDbCommand命令中用到的参数列表&lt;/param&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;returns&gt;返回一个数值表示此OleDbCommand命令执行后影响的行数&lt;/returns&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params OleDbParameter[] commandParameters)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OleDbCommand cmd = new OleDbCommand();</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (OleDbConnection conn = new OleDbConnection(connectionString))<BR>&nbsp;&
问题补充: 不好意思,俺也不知道咋回事,代码发不出来。只好放在这里了:http://www.cnblogs.com/dczsf/archive/2008/04/30/1177285.html 麻烦大家移步,谢谢了~
张少峰的主页 张少峰 | 菜鸟二级 | 园豆:320
提问于:2008-04-30 09:50
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册