Disable / Clear OleDbConnection Cache

I fought for OleDbConnectiona while, trying to get him not to cache. Basically I get access to the shared database, which is being written from another application, and then I read the values ​​(checking that it is cleared after the time of the last record and the subsequent 1 second delay).

Unfortunately, this is completely unreliable.

I read (and lose my mind) how to disconnect the connection pool, and then after each possible update I do the following before connecting again:

_connection.Close();
_connection.Dispose();
_connection = null;
OleDbConnection.ReleaseObjectPool();
GC.Collect();

In addition to this, the connection string disables pooling with OLE DB Services = -2. Finally, I also changed PageTimeoutto '10' in the registry for Jet 4.0.

All these measures, unfortunately, have no effect. Now, the only thing I can think of is what Microsoft KB mentions in this article and calls JRO.JetEngine.RefreshCache. The only problem is that argument ADODB.Connection. I would prefer not to rewrite my entire database level and where the records are read by my software in order to use an obsolete COM object to have this function, but it seems that this may be the only way.

My question is that this task is currently being rewritten to use ADODB (even ADO.NET!), Is it possible to disable caching OleDbConnection?

+8
source share
3 answers

, : OdbcConnection OleDbConnection.

:

string mdbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + mdbFile + ";OLE DB Services=-2";
using (OleDbConnection conn = new OleDbConnection(mdbConnectionString)) {
    conn.Open();
    //Do your query
}

:

string mdbConnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + mdbFile;
using (OdbcConnection conn = new OdbcConnection(mdbConnectionString)) {
    conn.Open();
    //Do your query
}

.

+1

, , "; Jet OLEDB: Flush Transaction Timeout" 0 .

.

0

32-

32- # , :

public static void RefreshDatabaseCache(
    string connectionString)
{
    // The type of the ADODB connection. Used for dynamically creating.
    var adodbType = Type.GetTypeFromProgID(@"ADODB.Connection");

    // The main ADODB connection object.
    var adodbInstance = Activator.CreateInstance(adodbType);

    // --

    // Open the connection.
    adodbType.InvokeMember(
        @"Open",
        BindingFlags.InvokeMethod,
        null,
        adodbInstance,
        new object[]
        {
            connectionString,
            string.Empty,
            string.Empty,
            0
        });

    try
    {
        // The type of the JET engine. Used for dynamically creating.
        var jroType = Type.GetTypeFromProgID(@"JRO.JetEngine");

        // The main JET engine object.
        var jroInstance = Activator.CreateInstance(jroType);

        // Refresh the cache.
        jroType.InvokeMember(
            @"RefreshCache",
            BindingFlags.InvokeMethod,
            null,
            jroInstance,
            new[]
            {
                adodbInstance
            });
    }
    finally
    {
        // Close the connection.
        adodbType.InvokeMember(
            @"Close",
            BindingFlags.InvokeMethod,
            null,
            adodbInstance,
            new object[]
            {
            });
    }
}

OleDB , , "ADODB".

64-

64- # - , .

0

All Articles