views:

1560

answers:

3

Hello. First sorry for my bad english but I'll try my best.

Right now I'm programming a .net application using Access 2007 as datastore.

In a nutshell: I have two threads. One thread inserts a row with a transaction into a table. The other thread updates many rows in constant intervals.

Thread 1

Database db = _loggingDatabase;

using (DbConnection conn = db.CreateConnection())
{
    conn.Open();
    DbTransaction txn = conn.BeginTransaction();
try
{
    string qryInsert = "Insert this";
    DbCommand cmdIns = db.GetSqlStringCommand(qryInsert);
    db.ExecuteNonQuery(cmdIns, txn);
    txn.Commit();
}
catch (Exception ex)
{
    txn.Rollback();
    throw ex;
}
finally
{
    conn.Close();
}

Thread 2

 Database db = _loggingDatabase;

    using (DbConnection conn = db.CreateConnection())
    {
        conn.Open();
        DbTransaction txn = conn.BeginTransaction();
    try
    {
        string qryUpdate = "Update that";
        DbCommand cmdUpdt = db.GetSqlStringCommand(qryUpdate);
        db.ExecuteNonQuery(cmdUpdt, txn);
        txn.Commit();
    }
    catch (Exception ex)
    {
        txn.Rollback();
        throw ex;
    }
    finally
    {
        conn.Close();
    }

If I trigger to insert many records I'll get an System.Data.OleDb.OleDbException which says: "Could not update; currently locked". I tried to change the Connectionstring to

connectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source=datastore.accdb; Jet OLEDB:Database Locking Mode=1;"

with no effects on my application behavior. I descided to uses those transactions to avoid chaotic inserts and updates.

Is there a workaround? What am I doing wrong? Can I insert my transactions to some kind of transaction queue into Access? Why isn't Access doing this by itselft?

A: 

Use MARS(Multiple Active Resultsets) in this case. Search on net for how to implement MARS.

Samiksha
A: 

Not sure if this will help but this article may help explain how to handle the fact that the "Microsoft Jet database engine has a read cache and lazy writes":

How To Implement Multiuser Custom Counters in Jet

onedaywhen
+1  A: 

Stefan Gruber asked:

Can I insert my transactions to some kind of transaction queue into Access? Why isn't Access doing this by itselft?

I think you are failing to understand the Jet database engine. First off, a clarification: MS may use "MS Access" as the name in it's ODBC and OLEDB connection strings, but you're not using Access at all in that case -- just Access's default database engine, Jet.

Jet is not a server database engine. That is, there is no server process standing between clients and the MDB file where the data is stored. All "users" of an MDB file are accessing it via the file system. To manage multi-user access, there is a locking file (the LDB file) that keeps track of what tables/records are locked and what kinds of locks. Jet checks that LDB file in order to determine what it can and cannot do.

Now, because there is no server-level process to manage all interaction with the on-disk data, there is no possibility of there ever being any marshalling of the requests for access to the MDB file. Your app has to do that itself.

If that is unsatisfactory, then you're using the wrong data store.

--
David W. Fenton
David Fenton Associates

David-W-Fenton