Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

ado.net - Access 2007 - INSERT and instant SELECT doesn't retrieve the inserted data

I'm inserting a few rows in a table via OleDB, and select instantly the inserted row.

I can't retrieve the row in this way, i have to wait for approx. 3-5 seconds. And then the inserted row appears in the table.

I observed this behavior in the database itself, i inserted the row via OleDB and watched the opened table in Access. The row appeared 3-5 seconds later in the table.

Does Access buffer rows? Do i have to send a flush or commit, etc. via OleDB ?

Any suggestions would be very helpful.

(Please don't ask why I don't solve this through my business logic or other ways....)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I did some testing and there does seem to be some buffering going on with ACE OleDb. I found that

  1. If I did some INSERTs and then immediately did a SELECT on the same OleDbConnection the new rows were available right away.

  2. If I opened two OleDbConnection objects, INSERTed on con1, and then immediately SELECTed on con2 the new rows took approximately 5 seconds to become available on the con2 connection.

  3. If I opened two OleDbConnection objects, INSERTed on con1, did con1.Close(), and then immediately SELECTed on con2 the new rows were available right away.

So, it appears that closing the OleDbConnection has the effect of "flushing" the writes and making them available to other connections sooner. My guess is that OleDb is implicitly buffering (or "batching") updates because ACE/Jet is a shared-file database and it is trying to reduce the contention on the database file.

(When I did the same test using SQL Server there was no significant difference between the case when I closed con1 and the case when I left it open. In every case the new records were available instantly.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...