日期:2014-05-18  浏览次数:20848 次

C#连接Access数据库,在IIS中报未知错误,但用VS自带的服务器正常。
connectionString为:Provider=Microsoft.Jet.OleDb.4.0;Data Source=E:\PRIVATE\ESTown ACCESS\Web\App_Data\enstom.mdb
SQLString为:select userId,userLoginName,userLoginPassWord,userName,userTelNo,userEmail,userType,userAdd,userRemark FROM userTable where userLoginName = 'admin'
代码如下:
C# code

  /// <summary>
        /// 执行查询语句,返回DataSet
        /// </summary>
        /// <param name="SQLString">查询语句</param>
        /// <returns>DataSet</returns>
        public static DataSet Query(string SQLString)
        {
            using (OleDbConnection connection = new OleDbConnection(connectionString))
            {
                DataSet ds = new DataSet();
                try
                {
                    connection.Open();
                    OleDbDataAdapter command = new OleDbDataAdapter(SQLString, connection);
                    command.Fill(ds, "ds");
                }
                catch (System.Data.OleDb.OleDbException ex)
                {
                    throw new Exception(ex.Message);
                }
                return ds;
            }
        }



在跟踪时发现,是connection.Open()抛出错误,但是只是在IIS下抛出,在VS自带的服务器下运行正常。


IE显示的错误信息:


“/ESTownAccess”应用程序中的服务器错误。
--------------------------------------------

未指定的错误 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Exception: 未指定的错误

源错误: 


行 320: catch (System.Data.OleDb.OleDbException ex)
行 321: {
行 322: throw new Exception(ex.Message);
行 323: }
行 324: return ds;
 

源文件: E:\PRIVATE\ESTown ACCESS\DBUtility\DbHelperOleDb.cs 行: 322 

堆栈跟踪: 


[Exception: 未指定的错误]
  Maticsoft.DBUtility.DbHelperOleDb.Query(String SQLString) in E:\PRIVATE\ESTown ACCESS\DBUtility\DbHelperOleDb.cs:322
  Fly.ESTown.DAL.userTable.GetList(String strWhere) in E:\PRIVATE\ESTown ACCESS\DAL\userTable.cs:208
  Fly.ESTown.BLL.userTable.GetList(String strWhere) in E:\PRIVATE\ESTown ACCESS\BLL\userTable.cs:90
  Fly.ESTown.BLL.userTable.IsAuthenticated(String strUserLoginName, String strUserLoginPassword) in E:\PRIVATE\ESTown ACCESS\BLL\userTable.cs:189
  Fly.ESTown.Web.Admin.Login.Login1_Authenticate(Object sender, AuthenticateEventArgs e) in E:\PRIVATE\ESTown ACCESS\Web\Admin\Login.aspx.cs:30
  System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +108
  System.Web.UI.WebControls.Login.AttemptLogin() +115
  System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
  System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
  System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
  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) +1565

 


<