各位大哥大姐,我做的单位的一个简单的办公系统用一段时间(或许一二个星期、或许三五天不定期)出现错误,不知如何解决(重启服务器后正常)请各位帮帮忙,谢谢。以下是IE上显示的错误信息:
//////////////////////////////////////////////////////////////////////
Server Error in '/oa' 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.Data.OleDb.OleDbException: 未指定的错误Source Error:
Line 60: string connstr="Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("#sdfsdf44564sfds3f45sdfwefs36sdfsdfd.mdb");
Line 61: conn=new OleDbConnection(connstr);
Line 62: conn.Open();
Line 63: string sqlstr="select * from members where Usernames='"+yhm.Text+"' and Userpwd='"+mm.Text+"'";
Line 64: cmd=new OleDbCommand(sqlstr,conn);
Source File: d:\oa\default.aspx Line: 62 Stack Trace:
[OleDbException (0x80004005): 未指定的错误]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +271
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +87
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +70
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +116
System.Data.OleDb.OleDbConnection.Open() +39
ASP.default_aspx.button1_click(Object sender, EventArgs e) in d:\oa\default.aspx:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +107
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3414
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
//////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
Server Error in '/oa' 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.Data.OleDb.OleDbException: 未指定的错误Source Error:
Line 60: string connstr="Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("#sdfsdf44564sfds3f45sdfwefs36sdfsdfd.mdb");
Line 61: conn=new OleDbConnection(connstr);
Line 62: conn.Open();
Line 63: string sqlstr="select * from members where Usernames='"+yhm.Text+"' and Userpwd='"+mm.Text+"'";
Line 64: cmd=new OleDbCommand(sqlstr,conn);
Source File: d:\oa\default.aspx Line: 62 Stack Trace:
[OleDbException (0x80004005): 未指定的错误]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +271
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +87
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +70
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +116
System.Data.OleDb.OleDbConnection.Open() +39
ASP.default_aspx.button1_click(Object sender, EventArgs e) in d:\oa\default.aspx:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +107
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3414
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
//////////////////////////////////////////
解决方案 »
- vs2010比vs2008更占用资源吗?机器比较老,能有2008,用2010会吃力吗?
- 不安装Microsoft .NET Framework 怎么运行客户端程序
- 自定义控件(WinForm)动态添加时无法显示
- 谁帮我看看这个正则表达式应该怎么写啊?
- insert表里有自增1字段应该如何操作呢
- 怎样用ado.net连接带有密码保护的excel?
- 关于xmlhttp获取远程webservice的问题,孟子老大来帮帮忙
- string.format 问题
- 请问如何让一个窗体启动时就是最大化的?
- dts全局变量问题:
- 打开外部编辑器编辑文本后,如何检查文本是否有改动?
- 求助:VS 2005 C# 编写PPC程序时,怎么让光标跳出TextBox,选择控制其它Button控件呢?
事件类型: 警告
事件来源: ASP.NET 2.0.50727.0
事件种类: Web Event
事件 ID: 1309
日期: 2010-5-10
事件: 14:39:48
用户: N/A
计算机: SERVER1
描述:
Event code: 3005 Event message: An unhandled exception has occurred. Event time: 2010-5-10 14:39:48 Event time (UTC): 2010-5-10 6:39:48 Event ID: 60e20011a57945a1bcc1755d9f5a0adf Event sequence: 2878 Event occurrence: 25 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/Root/oa-1-129179211092343750 Trust level: Full Application Virtual Path: /oa Application Path: D:\oa\ Machine name: SERVER1 Process information: Process ID: 30524 Process name: w3wp.exe Account name: NT AUTHORITY\NETWORK SERVICE Exception information: Exception type: OleDbException Exception message: 未指定的错误 Request information: Request URL: http://*****/Default.aspx Request path: /oa/Default.aspx User host address: 192.168.1.86 User: Is authenticated: False Authentication Type: Thread account name: NT AUTHORITY\NETWORK SERVICE Thread information: Thread ID: 1 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at ASP.default_aspx.button1_click(Object sender, EventArgs e) in d:\oa\default.aspx:line 62
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details: 有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。
但是一旦执行一个有问题的SQL语句就会抛出Exception,connection就不会得到关闭,那么以后再执行的话就会出问题,建议使用
using(OleDbConnection connection=new OleDbConnection())
{
}
这种方式,即使执行过程中出现异常也会关闭connection。
zhoufoxcn您好,能不能请您示范一下如何用USING的形式写一个更新数据库的代码?我也觉得是数据库没关闭成功的原因,或者如xuld222所说,某个地方出错了,导致连接数满了,但因为这个错误是不定期出现的,实在不好查啊。
try
{
//执行
}
catch
{
//这里的会抛出异常
}
finally
{
//关闭链接
}
catch (Exception exp)
{
exp.ToString();//这里就是异常的信息,便于调试,当然你也可以
}
catch
{
response.write("错误,请联系管理员");
}
catch
{
//这里的会抛出异常
}出现异常时这段内容才会被显示?正常时这里是不执行的吗?
/// 执行一个查询,并返回查询结果
/// </summary>
/// <param name="sql">要执行的SQL语句</param>
/// <param name="commandType">要执行的查询语句的类型,如存储过程或者SQL文本命令</param>
/// <param name="parameters">Transact-SQL 语句或存储过程的参数数组</param>
/// <returns></returns>
public DataTable ExecuteDataTable(string sql, CommandType commandType, SqlParameter[] parameters)
{
DataTable data = new DataTable();//实例化DataTable,用于装载查询结果集
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(sql, connection))
{
command.CommandType = commandType;//设置command的CommandType为指定的CommandType
//如果同时传入了参数,则添加这些参数
if (parameters != null)
{
foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add(parameter);
}
}
//通过包含查询SQL的SqlCommand实例来实例化SqlDataAdapter
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(data);//填充DataTable
}
}
return data;
}
=======================
<script language="C#" runat="server">
OleDbConnection conn;
OleDbCommand cmd;
void Page_Load(Object sender,EventArgs e)
{
if(Session["Username"]!=null)
{
Response.Redirect("alllogin.aspx");
}
}void button1_click(Object sender,EventArgs e)
{
if(Page.IsValid)
{
string connstr="Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("#sdfsdf44564sfds3f45sdfwefs36sdfsdfd.mdb");
conn=new OleDbConnection(connstr);
conn.Open();
string sqlstr="select * from members where Usernames='"+yhm.Text+"' and Userpwd='"+mm.Text+"'";
cmd=new OleDbCommand(sqlstr,conn);
OleDbDataReader reader;
reader=cmd.ExecuteReader();
if(reader.Read())
{
Session["Username"]=reader["Usernames"];
Session.Timeout=50;
Response.Redirect("noreceive.aspx");
reader.Close();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
else
{
reader.Close();
cmd.Dispose();
conn.Close();
conn.Dispose();
label1.Text="用户名或密码错误,请重新输入";
mm.Text="";
}
}
}
</script>
刚开始运行没事,但时间长了发生访问冲突了,我感觉access好象不支持并发访问!
如果条件允许我觉着还是用SQL SERVER更专业些!
也有可能是程序发生异常时未正常关闭access数据库
将大部分业务逻辑封装到存储过程中去,同时也避免了SQL 注入的问题了.
另外,不论什么类型的数据,数据库连接对象之类的东西使用完毕一定要释放掉.