各位前辈,网站发布到服务器上以后,浏览几分钟,过会就会出现下面的错误。
百度以后,有说权限问题的,但是这个是购买的空间,我设定不了。实在是想不出来,有的人说解决了但是没有说解决方法
所以请大家帮忙看看到底是什么愿意啊?谢谢!
Server Error in '/' Application.未指定的错误Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: 未指定的错误Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace:
[Exception: 未指定的错误]
DAL.DbHelperOleDb.ExecuteReader(String strSQL) in D:\Programme\BiologyWeb\Tsingke\DAL\DbHelperOleDb.cs:264
DAL.DALPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\DAL\DALPromotion.cs:28
BLL.BLLPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\BLL\BLLPromotion.cs:24
Tsingke.Web.product1.Page_Load(Object sender, EventArgs e) in D:\Programme\BiologyWeb\Tsingke\Tsingke\Web\product.aspx.cs:50
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
百度以后,有说权限问题的,但是这个是购买的空间,我设定不了。实在是想不出来,有的人说解决了但是没有说解决方法
所以请大家帮忙看看到底是什么愿意啊?谢谢!
Server Error in '/' Application.未指定的错误Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: 未指定的错误Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace:
[Exception: 未指定的错误]
DAL.DbHelperOleDb.ExecuteReader(String strSQL) in D:\Programme\BiologyWeb\Tsingke\DAL\DbHelperOleDb.cs:264
DAL.DALPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\DAL\DALPromotion.cs:28
BLL.BLLPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\BLL\BLLPromotion.cs:24
Tsingke.Web.product1.Page_Load(Object sender, EventArgs e) in D:\Programme\BiologyWeb\Tsingke\Tsingke\Web\product.aspx.cs:50
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
{
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
OleDbDataReader myReader = cmd.ExecuteReader();
cmd.Parameters.Clear();
return myReader;
}
catch (System.Data.OleDb.OleDbException e)
{
throw new Exception(e.Message);
}
finally
{
cmd.Clone();
cmd.Dispose();
connection.Close();
connection.Dispose();
} }不知道这样写是否可以,帮忙看看,谢谢。
或者直接就用DataAdapter来 返回dataset
我在前台创建调用这个方法的时候用了using。应该是强制释放了吧?
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
//创建一个SqlCommand对象
SqlCommand cmd = new SqlCommand();
//创建一个SqlConnection对象
SqlConnection conn = new SqlConnection(connectionString); //在这里我们用一个try/catch结构执行sql文本命令/存储过程,因为如果这个方法产生一个异常我们要关闭连接,因为没有读取器存在,
//因此commandBehaviour.CloseConnection 就不会执行
try {
//调用 PrepareCommand 方法,对 SqlCommand 对象设置参数
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
//调用 SqlCommand 的 ExecuteReader 方法
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//清除参数
cmd.Parameters.Clear();
return reader;
}
catch {
//关闭连接,抛出异常
conn.Close();
throw;
}
}在catch块中关闭连接 而不是在finally中
--------------------------------------------------------------------------------Unspecified error
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Exception: Unspecified errorSource Error:
Line 276: {
Line 277: connection.Close();
Line 278: throw new Exception(e.Message);
Line 279: }
Line 280: }
Source File: D:\Programme\BiologyWeb\Tsingke\DAL\DbHelperOleDb.cs Line: 278 Stack Trace:
[Exception: Unspecified error]
DAL.DbHelperOleDb.ExecuteReader(String strSQL) in D:\Programme\BiologyWeb\Tsingke\DAL\DbHelperOleDb.cs:278
DAL.DALPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\DAL\DALPromotion.cs:28
BLL.BLLPromotion.GetShowPromotions(Int32 topNo) in D:\Programme\BiologyWeb\Tsingke\BLL\BLLPromotion.cs:24
Tsingke.index2.Page_Load(Object sender, EventArgs e) in D:\Programme\BiologyWeb\Tsingke\Tsingke\index.aspx.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 我是用本地的IIS7发布的,报错是上面的信息,报错后多几分钟,再刷新就正常了,总是在反复。
Line 276: {
Line 277: connection.Close();
Line 278: throw e;
Line 279: }
Line 280: }
跟我一样的症状。
// {
connection.Open();
OleDbDataReader myReader = cmd.ExecuteReader();
return myReader;
去掉以后,他报错的就是 connection.Open(); 然后其他的都一样了。
Command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); 枚举第一个为默认的System.Data.CommandBehavior.CloseConnection 的意思就是 while(Idatareader.Read())读取完之后自动关闭连接
如果不把数据库连接关掉 那么用什么数据库都是白搭
这就说明你删除了自己写的坑爹的try...catch...之后,终于循着正确的方向去找异常了。怎么你还是纠结在什么“关闭”问题上呢?