各位大哥大姐,我做的单位的一个简单的办公系统用一段时间(或许一二个星期、或许三五天不定期)出现错误,不知如何解决(重启服务器后正常)请各位帮帮忙,谢谢。以下是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
//////////////////////////////////////////

解决方案 »

  1.   

    以下是服务器事件查看器上显示的错误信息////////////////////////////////////////////////////
    事件类型: 警告
    事件来源: 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 的帮助和支持中心。
      

  2.   

    光看这个看不出来,是否当时有人手工打开了mdb?
      

  3.   

    没有人手工打开MDB,我也检查过网页里打开数据库的地方用过后都关了的
      

  4.   

    在大部分情况下上面的代码是没有问题的,connection能得到关闭。
    但是一旦执行一个有问题的SQL语句就会抛出Exception,connection就不会得到关闭,那么以后再执行的话就会出问题,建议使用
    using(OleDbConnection connection=new OleDbConnection())
    {
    }
    这种方式,即使执行过程中出现异常也会关闭connection。
      

  5.   

    谢谢楼上的各位大侠热心回答。
    zhoufoxcn您好,能不能请您示范一下如何用USING的形式写一个更新数据库的代码?我也觉得是数据库没关闭成功的原因,或者如xuld222所说,某个地方出错了,导致连接数满了,但因为这个错误是不定期出现的,实在不好查啊。
      

  6.   

    或者你也可以使用 try catch  
      

  7.   

    谢谢deknight,因为我也是刚接触C#,不太熟,我去找找资料看一下
      

  8.   


    try
                {
    //执行
                }
                catch
                {
    //这里的会抛出异常
                }
                finally
                { 
                    //关闭链接
                }
      

  9.   

    谢谢deknight热心人,是不是所有涉及的数据库操作的地方都要换成这个形式的啊/
      

  10.   

    try catch的作用是 如果有异常,可在catch处将异常抛出便于查看,finally是无论怎样,最终都要执行的部分
    catch (Exception exp)
                {
                    exp.ToString();//这里就是异常的信息,便于调试,当然你也可以
                }
    catch
    {
       response.write("错误,请联系管理员");
    }
      

  11.   

    谢谢deknight,也就是说
    catch
                {
    //这里的会抛出异常
                }出现异常时这段内容才会被显示?正常时这里是不执行的吗?
      

  12.   

    对,catch就是当遇到错误时你要怎么做,你可以显示出异常的具体内容,或是自己写个什么去显示
      

  13.   

    一个using用法的例子:/// <summary>   
            /// 执行一个查询,并返回查询结果   
            /// </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;   
            }  
      

  14.   

    感谢楼上几位大哥,周末试了下,今天上班还是出现了问题。我想问一下,我下面这段代码会不会有问题啊?
    =======================
    <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>
      

  15.   

    会不会是多线程访问access数据库出现冲突造成的?
    刚开始运行没事,但时间长了发生访问冲突了,我感觉access好象不支持并发访问!
    如果条件允许我觉着还是用SQL SERVER更专业些!
      

  16.   

    应该不会吧?ACCESS再弱也不至于这样吧?还请高手帮我看看上面的那段代码会不会有问题啊,谢谢。
      

  17.   

    使用完未正常关闭
    也有可能是程序发生异常时未正常关闭access数据库
      

  18.   

    对于一个OA系统而言,最好使用MS SQL 数据库.
    将大部分业务逻辑封装到存储过程中去,同时也避免了SQL 注入的问题了.
    另外,不论什么类型的数据,数据库连接对象之类的东西使用完毕一定要释放掉.