上传的一个ASP.NET多刷新几次就会出现下面这个问题

问题错误图:




就是上传时是正常的!后来运行然后多点几个页面时就会出现上面这个问题的;


用的数据库是ACCESS的;


数据库操作类的为下面:会不会是数据库没有连接没有关闭啊!下面这个要类要怎么改啊





using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;

/// <summary>
///accessDB 的摘要说明
/// </summary>
public class AccessDbClass
{

  //变量声明处#region 变量声明处
  public OleDbConnection Conn;
  public string ConnString;//连接字符串

  /// <summary>
  /// 构造函数
  /// </summary>
  public AccessDbClass()
  {
  ConnString = ConfigurationSettings.AppSettings["OLEDBCONNECTIONSTRING"] + HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["dbPath"]);
  Conn = new OleDbConnection(ConnString);
  Conn.Open();
  }


  //构造函数与连接关闭数据库#region 构造函数与连接关闭数据库
  /// <summary>
  /// 构造函数
  /// </summary>
  /// <param name="Dbpath">ACCESS数据库路径-webconfig中自定义</param>
  public AccessDbClass(string DBpath)
  {
  ConnString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString + System.AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.ConnectionStrings[DBpath].ConnectionString;
  Conn = new OleDbConnection(ConnString);
  Conn.Open();
  }  



  /// <summary>
  /// 打开数据源链接
  /// </summary>
  /// <returns></returns>
  public OleDbConnection DbConn()
  {
  Conn.Open();
  return Conn;
  }

  /// <summary>
  /// 请在数据传递完毕后调用该函数,关闭数据链接。
  /// </summary>
  public void Close()
  {
  Conn.Close();
  }


  /// 数据库基本操作#region 数据库基本操作
  /// <summary>
  /// 根据SQL命令返回数据DataTable数据表,
  /// 可直接作为dataGridView的数据源
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public DataTable SelectToDataTable(string SQL)
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  OleDbCommand command = new OleDbCommand(SQL, Conn);
  adapter.SelectCommand = command;
  DataTable Dt = new DataTable();
  adapter.Fill(Dt);
  return Dt;
  }

  /// <summary>
  /// 根据SQL命令返回数据DataSet数据集,其中的表可直接作为dataGridView的数据源。
  /// </summary>
  /// <param name="SQL"></param>
  /// <param name="subtableName">在返回的数据集中所添加的表的名称</param>
  /// <returns></returns>
  public DataSet SelectToDataSet(string SQL, string subtableName)
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  OleDbCommand command = new OleDbCommand(SQL, Conn);
  adapter.SelectCommand = command;
  DataSet Ds = new DataSet();
  Ds.Tables.Add(subtableName);
  adapter.Fill(Ds, subtableName);
  return Ds;
  }

  /// <summary>
  /// 在指定的数据集中添加带有指定名称的表,由于存在覆盖已有名称表的危险,返回操作之前的数据集。
  /// </summary>
  /// <param name="SQL"></param>
  /// <param name="subtableName">添加的表名</param>
  /// <param name="DataSetName">被添加的数据集名</param>
  /// <returns></returns>
  public DataSet SelectToDataSet(string SQL, string subtableName, DataSet DataSetName)
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  OleDbCommand command = new OleDbCommand(SQL, Conn);
  adapter.SelectCommand = command;
  DataTable Dt = new DataTable();
  DataSet Ds = new DataSet();
  Ds = DataSetName;
  adapter.Fill(DataSetName, subtableName);
  return Ds;
  }

  /// <summary>
  /// 专门用来分页控件AspNetPage使用
  /// </summary>
  /// <param name="commandText">要执行的SQL语句</param>
  /// <param name="AspNetPageSize">AspNetPage第一个参数</param>
  /// <param name="PageSize">AspNetPage一页有几个</param>
  /// <param name="TableName">表名</param>
  /// <returns>DataTable</returns>
  public DataTable SelectToAspnetPage(string commandText, int AspNetPageSize, int PageSize, string TableName)
  {
  DataSet ds = new DataSet();
  using (OleDbDataAdapter adapter = new OleDbDataAdapter(commandText,Conn))
  {
  adapter.Fill(ds, AspNetPageSize, PageSize, TableName);
  return ds.Tables[TableName];
  }
  }

  /// <summary>
  /// 根据SQL命令返回OleDbDataAdapter,
  /// 使用前请在主程序中添加命名空间System.Data.OleDb
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public OleDbDataAdapter SelectToOleDbDataAdapter(string SQL)
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  OleDbCommand command = new OleDbCommand(SQL, Conn);
  adapter.SelectCommand = command;
  return adapter;
  }

  /// <summary>
  /// 执行SQL命令,不需要返回数据的修改,删除可以使用本函数
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public bool ExecuteSQLNonquery(string SQL)
  {
  OleDbCommand cmd = new OleDbCommand(SQL, Conn);
  try
  {
  cmd.ExecuteNonQuery();
  return true;
  }
  catch
  {
  return false;
  }
  }

  public bool ExecuteInsertNonquery(string SQL)
  {
  OleDbCommand cmd = new OleDbCommand(SQL, Conn);
  int count =Convert.ToInt32(cmd.ExecuteNonQuery());
  if (count > 0)
  {
  return true;
  }
  else
  {
  return false;
  }
  }

  /// <summary>
  /// 执行SQL命令,数据是否存在,返回bool
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public bool Exists(string SQL)
  {
  OleDbCommand cmd = new OleDbCommand(SQL, Conn);
  int count = Convert.ToInt32(cmd.ExecuteScalar());
  if (count > 0)
  {
  return true;
  }
  else
  {
  return false;
  }
  }

  /// <summary>
  /// 执行SQL命令,数据返回当前值,返回INT
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public int ExistsCount(string SQL)
  {
  OleDbCommand cmd = new OleDbCommand(SQL, Conn);
  int count = Convert.ToInt32(cmd.ExecuteScalar());
  return count;
  }



  /// <summary>
  /// 执行SQL命令,查询记录总数,返回int
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public int MaxCount(string SQL)
  {
  OleDbCommand cmd = new OleDbCommand(SQL, Conn);
  int count = Convert.ToInt32(cmd.ExecuteScalar());
  if (count > 0)
  {
  return count;
  }
  else
  {
  return 0;
  }
  }
   
}






页面调用:

 AccessDbClass accessHelp = new AccessDbClass();
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  string SqlSiteInfo = "select * from T_ComparyProfile where Langery='ZH'";
  DataTable SiteTable = accessHelp.SelectToDataTable(SqlSiteInfo);
  if (SiteTable.Rows.Count > 0)
  {
  this.li_Conf.Text = SiteTable.Rows[0]["Context"].ToString();
  }

  accessHelp.Close(); }
  }

作者: WJY258378100   发布时间: 2011-06-16

Conn.Open(); 这些东西不能移到你的方法里?

  C# code
try
            {
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }

作者: wxr0323   发布时间: 2011-06-16

能不能在上面那个类做修改不???

作者: WJY258378100   发布时间: 2011-06-16

在IIS 里面把项目的属性弹出的对话框, 重建应用一下试试!

作者: zds835   发布时间: 2011-06-16

这问题 应该是Acceess数据库列所命名的与系统数据库关键字相冲突引起的。你可以把与关键字的列名 用 []弄起来就好了
  如果不是这个问题的话 那就是
在web.config中
<system.web>
 <identity impersonate="true"/>//改为false
 </system.web>

作者: wosizy   发布时间: 2011-06-16

C# code

/// 数据库基本操作#region 数据库基本操作
  /// <summary>
  /// 根据SQL命令返回数据DataTable数据表,
  /// 可直接作为dataGridView的数据源
  /// </summary>
  /// <param name="SQL"></param>
  /// <returns></returns>
  public DataTable SelectToDataTable(string SQL)
  {
  OleDbDataAdapter adapter = new OleDbDataAdapter();
  OleDbCommand command = new OleDbCommand(SQL, Conn);
  adapter.SelectCommand = command;
  DataTable Dt = new DataTable();
  adapter.Fill(Dt);
[color=#FF0000]  Conn.Close();[/color]
  return Dt;
  }

作者: yyl8781697   发布时间: 2011-06-16