Access DB in network folder cannot be read by ASP.NET
Asked Answered
S

2

0

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];
    }
}
Sniper answered 4/3, 2013 at 17:38 Comment(2)
Take a look at #1938203. Namely strDdl = "GRANT SELECT ON MSysObjects TO Admin;" CurrentProject.Connection.Execute strDdlHarvin
@Syn123 That gives me an error, even when I try to do it on a local copy: You do not have the necessary permissions to use the '' object. Have your system administrator or the person who created this object establish the appropriate permissions for you. Ideas how to get around that? Maybe because mine is MDB and that question was ACCDB?Sniper
S
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:

enter image description here

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

Sniper answered 4/3, 2013 at 19:40 Comment(0)
P
0

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.

Perigee answered 4/3, 2013 at 17:42 Comment(3)
Right now I'm still just trying to access it from Visual Studio debugging. I don't think that has a service account associated with it. Do you know what it is running as?Sniper
What version of .net Framework? I'm guessing it is running under a local service account. something like computername\ASPNET.Perigee
Framework version = .net 4.0. How can I tell what service accounts are running on my machine?Sniper

© 2022 - 2024 — McMap. All rights reserved.