为什么刷新网页,或进入下一页时,会出现下面这种错误?
异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误 源错误:
行 27: {
行 28:
行 29: conn.Open();
行 30:
行 31: }
当我把Web.Config文件的 <compilation debug="true"> 改成 <compilation debug="false">时又可以了,或者移走其中一个文件也可以,但再次刷新,又出现另一个问题.怎么解决?谢谢!!有源码,请高手下载帮我看看!!
http://www.yuanshengkj.com/bbs/topic.asp?topic_id=1763&forum_id=26
异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误 源错误:
行 27: {
行 28:
行 29: conn.Open();
行 30:
行 31: }
当我把Web.Config文件的 <compilation debug="true"> 改成 <compilation debug="false">时又可以了,或者移走其中一个文件也可以,但再次刷新,又出现另一个问题.怎么解决?谢谢!!
http://www.yuanshengkj.com/bbs/topic.asp?topic_id=1763&forum_id=26
if(!ispostback)
{
//数据绑定操作
}
异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误
可能数据库连接出错~~
http://www.yuanshengkj.com/bbs/topic.asp?topic_id=1763&forum_id=26
各位高手麻烦帮我调试看看!!拜托了!!
conn.Close();
public class DB
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static OleDbConnection Getconn()
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ConnectionString"].ToString()));
if (conn.State.Equals(ConnectionState.Closed))
{ conn.Open(); }
return conn;
}
private static void closeConnection()
{
OleDbConnection conn = DB.Getconn();
OleDbCommand cmd = new OleDbCommand();
if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Dispose();
cmd.Dispose();
}
}
public static void binddatalist(string sql, DataList dl)
{
try
{
OleDbConnection conn = DB.Getconn();
DataSet ds = getdataset(sql);
dl.DataSource = ds.Tables[0].DefaultView;
dl.DataBind();
}
catch (Exception e)
{
throw new Exception(e.Message); }
finally
{
closeConnection();
}
}
}
在页面后台调用部分代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string topsql1 = "select top 8 * from info order by hits,id desc";//教育动态6和
DB.binddatalist(topsql1, this.DataList1);
string topsql2 = "select top 8 * from info order by hits,id desc";//焦点新闻
DB.binddatalist(topsql2, this.DataList2);
string topsql3 = "select top 8 * from info order by hits,id desc";//教育督导
DB.binddatalist(topsql3, this.DataList3);
string topsql4 = "select top 8 * from info order by hits,id desc";//办事指南
DB.binddatalist(topsql4, this.DataList4);
string topsql5 = "select top 8 * from info order by hits,id desc";//教育法规
DB.binddatalist(topsql5, this.DataList5);
string topsql6 = "select top 8 * from info order by hits,id desc";//文件通知
DB.binddatalist(topsql6, this.DataList6);
string topsql7 = "select top 16 * from info order by hits,id desc";//教育收费
}
}
完整源码下载地址:
http://www.yuanshengkj.com/bbs/topic.asp?topic_id=1763&forum_id=26
各位看看有什么问题?
select top 16 * from [info] order by hits,[id] desc2,并发数太大,access不喜欢。可以尝试只打开一次连接,执行全部查询,最后关闭一次。
修改 web.config 程序会重启,所以你发现它又好使了。
看了此帖14楼的Code,Insus.NET有另外的想法:
在DB的类别中,看到楼主有写一个函数:
public static void binddatalist(string sql, DataList dl)
{
//function code
}
这个函数有传两个参数,又是写在DB类别,Insus.NET觉得这样写,有与“开放-封闭”设计模式相违。前台代码与后台(逻辑层)代码耦合性太强。如果把DB封装之后,某一天,前台的表现形式由DataList改为GridView或是其他的话,程序需要改DB类了。
另外,在Page_Load前台,出现有SQL语句,Insus.NET觉得也不是很好,应该把这些SQL提升至逻辑层中的类别较为好。也许楼主现在所有前台后台均一人完成,也怪不得。下面是Insus.NET稍改了一下,请参考:public class DB
{
private string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ConnectionString"].ToString());
private OleDbConnection objConn;
private OleDbCommand objCmd;
private OleDbDataAdapter objDa; public void Execute(string strSql)
{
//......
objCmd.ExecuteNonQuery();
//.....
} public object ExecuteScalar(string strSql)
{
//......
return objCmd.ExecuteScalar();
//.....
} public DataSet ExecuteDataSet(string strSql)
{
objConn = new OleDbConnection(strConn);
objConn.Open();
objDa = new OleDbDataAdapter(strSql, objConn);
DataSet objds = new DataSet();
objDa.Fill(objds);
objConn.Close();
return objds;
} public SqlDataReader ExecuteDataReader(string strSql)
{
//.....
return objCmd.ExecuteReader();
}
}
public class Info
{
public Info()
{
//
// TODO: Add constructor logic here
//
} //焦点新闻
public DataTable GetFocusInfo()
{
DB objDb = new DB();
string strSql = "select top 8 * from info order by hits,id desc";
return objDb.ExecuteDataSet(strSql).Tables[0];
}
//教育督导
public DataTable GetTechInfo()
{
DB objDb = new DB();
string strSql = "select top 8 * from info order by hits,id desc";
return objDb.ExecuteDataSet(strSql).Tables[0];
} //Other Function or Void}客户端public partial class _Default : System.Web.UI.Page
{
//客户端即管new一个对象
Info objInfo = new Info();
protected void Page_Load(object sender, EventArgs e)
{
Data_Binding();
} private void Data_Binding()
{
//设计客户端的人,无需懂得sql,更无需知道sql语句,只管应用罗辑层的函数即可.
this.DataList1.DataSource = objInfo.GetFocusInfo();
this.DataList1.DataBind(); //不管客户端是用DataList也好,还是GridView也许,开发Info类别的逻辑层的人,也不用管客户端是怎样应用.只需把数据集的函数public即可.
this.GridView1.DataSource = objInfo.GetTechInfo();
this.GridView1.DataBind();
}
}