OleDBConnection to Access database "flushing" problem

W

William Sonner

Hi,

I'm writing in C# and using the OleDbConnection class to connect to a
Microsoft Access database. The provider used in the connection string is
"Provider=Microsoft.Jet.OLEDB.4.0".

I have two objects (A and B). The first object (Object A) uses an
OleDbConnection object to make a connection to an access database. It uses
an OleDbCommand object to populate one of the database tables by calling the
ExecuteNonQuery function repeatedly, then the database connection is closed.

After the above has completed, the second object (Object B) uses its own
OleDbConnection object to connect to the access database to make use of the
data populated by Object A. So, there are no shared database connections or
other means to "share" the data between objects A and B. This is by design.

THE PROBLEM:

The problem is, that after the code in Object A has completed and the
connection is closed, the Microsoft Jet Engine hasn't completely finished
writing the data to disk. When Object B connects to the database to read in
the data, it doesn't get all of it.

I have seen this happen before with the Microsoft Jet Engine when using the
MFC CDaoDatabase class. I had a work around then though. The CDaoDatabase
object had a CDaoWorkspace class member object which you could call its Idle
function. The CDaoWorkspace::Idle function could be called to "provide the
database engine with the opportunity to perform background tasks that may
not be up-to-date because of intense data processing." And this worked.

I am pretty sure that this is the problem because I put a short "sleep"
command in to delay starting Object B to allow the Jet Engine background
tasks associated with Object A to complete and that resolved the problem.
But it's ugly.

MY QUESTION:

My question is whether or not there is something similar to
CDaoWorkspace::Idle in the dot net frame work which would solve this
problem. And obviously, what is it?

Thank you,
Bill
 
B

bhawin13

Hello William Sonner,
I think your problem is you are using 2 different connection because
connection is executed in seperate threade that is the reason for your
problem.

If you use one connection then problem will be solved.
Still you face problem then use transaction with one connection
create connection

create transection object using connection object
myTrans = myConnection.BeginTransaction(IsolationLevel.Serializable)

assign this transection object to both command object and
myCommand.Transaction = myTrans

regards,
bhawin13
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top