4

I have a problem with a OleDbConnection accessing a .mdb File on a Windows share in the same network. When it gets disposed at the end of the using part, it needs more than 2 seconds for that. Opening the connection and executing the query or filling the DataTable only needs up to 50ms.

that's my code:

private const string DbConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;data source=\\server\share\file.mdb";
private const string DbConnectionStringIp = @"Provider=Microsoft.ACE.OLEDB.12.0;data source=\\192.168.1.1\\share\file.mdb";

using(var connection = new OleDbConnection())
{
    connection.ConnectionString = DbConnectionString;
    try
    {
        connection.Open();
    }
    catch(OleDbException)
    {
        connection.ConnectionString = DbConnectionStringIp;
        connection.Open();
    }

    const string query = "SELECT somefield FROM sometable WHERE someotherfield=1)";
    using(var command = new OleDbCommand(query, connection))
    {
        using(var adapter = new OleDbDataAdapter(command))
        {
            adapter.Fill(employees);
        }
    } 
//From Here 
}
//To Here => 2 seconds

Basically "From Here " to "To Here" is the most time consuming part of the Code. Do you have an Idea, why it's so slow?

halliba
  • 309
  • 2
  • 8
  • Hi halliba, did you ever find a solution for this? – Bassie Jun 12 '17 at 23:27
  • no I'm sorry. Back then a user gave me a hint, that a specific command executes very slow and I broke down the issue to the lines sown above. After a few days I resigned and used pre-cached results.. I Just ran the code in our environment and the error is still exists. I wish you luck, if you have the same problem ;) – halliba Aug 04 '17 at 08:48
  • I expect that it is a windows overhead, closing and releasing the file. How long does it take for the .ldb (lock) file in the shared folder to be disposed of? Is it the same speed if the .mdb file is on a local or non-shared drive? – trevor Oct 07 '19 at 10:19

1 Answers1

0

I also had this issue, except the performance was even worse (around 20 seconds to call Dispose). A suggestion from a related question resolved the issue: adding the following to the connection string:

OLE DB Services=-1;
Gurch
  • 49
  • 2