Access DB in network folder cannot be read by ASP.

2019-08-23 06:00发布

问题:

I have an ASP.NET page that needs to push some data to an older program that uses an Access 2003 database for a backend. I have my connection strings all set up to do this (successful to a local copy of the DB) but when I try to read from the database on its network share location, I get the following error:

Record(s) cannot be read; no read permission on 'tblDevice'.

There are no passwords or any security on the database, so I'm pretty sure this is network related. I'm not aware of any way to include a network login/password with the connection string. I would assume it's going to require adding a certain user to the folder. However, I'm not sure what user needs permission to that folder for it to work (both from Visual Studio and from IIS). Anyone had experience with this type of error or know what "users" need to be given permission to the folder?


My code for reference:

Access connection string

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\srv.local\SHAREDOCS\data.mdb;
    User Id=admin;Password=;

Selection Code

public static DataTable GetDevices(string serialNum)
{
    var conn = new OleDbConnection();
    var builder = new OleDbConnectionStringBuilder();
    builder.ConnectionString = ConfigurationManager.ConnectionStrings["development"].ToString();
    conn = builder.ConnectionString;

    var sqlString = "SELECT DeviceID, SN FROM tblDevice WHERE Active=True AND SN=@serialNum ORDER BY SN, DeviceID; "

    using (var cmd = new OleDbCommand(sqlString, conn))
    {
        cmd.Parameters.AddWithValue("@serialNum", serialNum);
        var ds = new DataSet();
        var da = new OleDbDataAdapter(cmd);

        da.Fill(ds);

        return ds.Tables[0];
    }
}

回答1:

Finally figured this out, and it was no where near what I expected. For some odd reason, the database had random differences in permission on the various tables. (Some had full access, some none, some mixed... no rhyme or reason from what I know about the way the program works.) To get to the permissions, I had to go here (Access 2010 but a 2003 MDB file):

File -> Info -> Users and Permissions -> User and Group Permissions...

That presented me with the following options:

All I had to do was check the appropriate permissions for each object and now it works.



回答2:

Check that your service account that your application pool is running under has permissions to the database. If your service account is running under does not have permission, then you would most likely run into an issue like this.