简体   繁体   中英

mdb file oledbconnection throws “The Microsoft Access database engine cannot open or write to the file …”

I'm writing a .Net Web Api that tries to read a .mdb file from a shared drive. But whenever I try to open the connection it gives me a

The Microsoft Access database engine cannot open or write to the file '\\myshareddrive\\thedatabase.mdb'. It is already opened exclusively by another user, or you need permission to view and write its data.

I've already changed my permissions on the folder and the file that involves the NETWORK SERVICE account to have modify access. I also messed with the IIS to "Connect as" a user that has admin rights on the shared drive. And yes the file is closed. Not sure where to go now. Any advice is appreciated.

I looked at this solution:

http://www.aspdotnet-suresh.com/2013/01/c-microsoft-office-access-database.html

Here's my code:

var databaseStringthatincludespath = "\\myshareddrive\thedatabase.mdb"
var connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + databaseStringthatincludespath;

try
{
    OleDbConnection Myconnection = new OleDbConnection(connString);
    Myconnection.Open();
    Myconnection.Close();
    return "Yo test return!";
}
catch (Exception ex)
{
    var error = ((ex.InnerException != null) ? ex.InnerException.Message : " ") + " -- " + ex.Message;
    return error;
}

Finally figured it out. Basically you need to make sure the "Authentication" of the app on your IIS to enable impersonation (at least this is the route I took). And make sure that the accoutn is recognized on the server where the path lies so that when the app gets executed as the impersonated account there won't be any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM