如何修复错误:发布到IIS后无法访问.mdb文件

时间:2019-01-18 10:00:26

标签: asp.net-mvc

调试时,我的项目可以访问.mdb文件,但是发布到IIS(Windows 10)后失败。

此文件放在项目管理区域的文件夹中。

我尝试过:为此文件的完全权限添加IIS_IUSRS用户的权限。

谁能告诉我如何解决此错误?谢谢!

   static string mapPath = "~/Areas/admin/dbAccess";
   static string mdbFileName = "\\att2000.mdb";        
   // GET: admin/WTS
    public List<SelectListItem> GetUserList()
    {
        string filepath = Server.MapPath(mapPath) + mdbFileName;
        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath;

        List<SelectListItem> resultUserList = new List<SelectListItem>();
        string strSQLuser = "SELECT u.NAME FROM USERINFO u";
        ViewBag.ResultUserList = "";
        using (OleDbConnection connection = new OleDbConnection(connectionString))
        {
            OleDbCommand command2 = new OleDbCommand(strSQLuser, connection);
            try
            {
                connection.Open();
                using (OleDbDataReader userLisrReader = command2.ExecuteReader())
                {
                    while (userLisrReader.Read())
                    {
                        SelectListItem userItem = new SelectListItem()
                        {
                            Text = userLisrReader["NAME"].ToString(),
                            Value = userLisrReader["NAME"].ToString()
                        };
                        resultUserList.Add(userItem);
                    }
                    ViewBag.CountItem = resultUserList.Count;
                    ViewBag.ResultUserList = resultUserList;
                }
            }
            catch (Exception)
            {
            }
        }
        return resultUserList;
    }

0 个答案:

没有答案