0

I am having some trouble connecting to an Access database which sits on a remote computer:

The Microsoft Access database engine cannot open or write to the file '\\ACCESSSERVER-PC\Warehouse Manager\Error Logging\Error Logging.accdb'. It is already opened exclusively by another user, or you need permission to view and write its data.

The database is not open for editing by anyone else and I should be able to connect to it.

I am using this connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\ACCESSSERVER-PC\Warehouse Manager\Error Logging\Error Logging.accdb;Persist Security Info=False;

And the error occurs when calling connOpen();

using (var conn = new OleDbConnection(ConnectionString))
{
    try
    {    
        conn.Open();
    }
}

I gave myself full permissions for the server as well as the .accdb file iteself, and did the same for the NETWORK SERVICE account as per this post, but still not luck.

I don't have a problem connecting to databases which are stored locally, and this only seems to be happening whent rying to conect over the network.

Has anyone else experienced this and found a solution? Any help or advice is much appreciated.

I have checked this answer and can confirm that I have all the required permissions to access the file.

That question is marked as a duplicate of this question, but I don't have any programs running which would have a stream open to the file.

Community
  • 1
  • 1
Bassie
  • 9,529
  • 8
  • 68
  • 159
  • 1
    Possible duplicate of [Error message : Access already exclusively by another user](http://stackoverflow.com/questions/7660592/error-message-access-already-exclusively-by-another-user) – iwaduarte Jan 24 '17 at 11:30
  • @iwaduarte I have granted full control permissions on both the folder and the access file for `SYSTEM`, `NETWORK SERVICE`, `IUSR`, and myself but still getting the same error – Bassie Jan 24 '17 at 11:32

1 Answers1

1

It turns out this was being caused by trying to work with some terrible IT infrastructure.

The issue is that \\ACCESSSERVER-PC is actually a Windows 7 machine and so can only handle a limited number of connections.

Running the IsLocked code from this answer against the database file gave me a much more useful error message:

No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept.

After getting some users to disconnect their Access runtime and mapped drives from the server and running the code again, IsLocked returned false and I was then able to connect to the database.

Here is the code I used to help me find the solution to this:

protected virtual bool IsFileLocked(FileInfo file)
{
    FileStream stream = null;

    try
    {
        stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
    }
    catch (IOException)
    {
        //the file is unavailable because it is:
        //still being written to
        //or being processed by another thread
        //or does not exist (has already been processed)
        // 
        // ** OR There are already too many connections open to the         
        // ** "server" where the file exists!
        return true;
    }
    finally
    {
        if (stream != null)
            stream.Close();
    }

    //file is not locked
    return false;
}

The moral of the story is Don't use (or work in an environment where they use) a Windows 7 machine as a server when you need 20+ concurrent connections to the server!

Community
  • 1
  • 1
Bassie
  • 9,529
  • 8
  • 68
  • 159