After oledb inset in Excel, 'Cannot Access file' error on Excel

  • Thread starter Thread starter Prachi
  • Start date Start date
P

Prachi

Hi,

I have C# code that uses Jet.OLEDB.4.0 to write to an excel file.
After performing inserts using an 'insert into' SQL query, I close the
connection and reopen the file using excel objects for performing some
other operations on the file.

If the data being written using oledb is large (more than 1K records),
excel throws an error 'Cannot Access File' while opening the file
using Excel objects. If the data is less around 500 records, the
exception is not thrown.

I feel the reason for exception is that before the file is released by
oledb, the excel objects try to operate on it.

How do I make sure that the oledb has finished its writing and the
file is released, so that excel does not throw exception.

Thanks & regards,
Prachi
 
Is there a background setting that allows the writing to be done
asynchronously - if so, set that to false so the code does not continue
until the writing is done.
 
Hi Tom,

Thanks a lot!! I did find a registry setting that enforces synchronous
writes on Oledb Jet provider.

Thanks again,
Prachi
 

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

Back
Top