Releasing dBase (OleDB) resources

Hello all.
I've digged Inted and found no answer for problem I found.
When I connect the dBase files, the directory where dbf files are stored cannot be removed anymore untill the process (application) is closed completly. Closing datareader, connection etc doesn't help.

a bit of code:

OleDbConnection conn_batch = null;
OleDbCommand cmd = null;
OleDbDataReader dr_batch = null;

conn_batch = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + data_dir + ";Extended Properties=DBASE IV;");
conn_batch.Open();

// here the data_dir directory can be still deleted

cmd = new System.Data.OleDb.OleDbCommand();
cmd.Connection = conn_batch;
cmd.CommandText = "SELECT * FROM BATCH"
dr_batch = cmd.ExecuteReader();

while (dr_batch.Read())
{
// reading fields
}

cmd = null;
dr_batch.Close();
dr_batch = null;
conn_batch.Close();
conn_batch = null;

// directory data_dir cannot be deleted!!!

The simmilar code with Access database works ok. Looks like bug for dBase or I missed something?

Best regards
Michal K.

[1167 byte] By [maxym_urt] at [2007-12-26]
# 1

Hi,

I guess if the server resource manager of visual studio have still connected to your database. close or remove in it and try again

regards

tangfx at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
It is not related to VS. Such behaviour persist when running exe. VS is closed.
maxym_urt at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3

hi,

I think the data_dir is made readonly by oledb driver, could you reset the directory re-writable in you program. here is some information about borland dbase from microsoft:

INF: How the dBASE Driver Performs Locking

http://support.microsoft.com/kb/95081/en-us

tangfx at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4
No. The directory is not set to read only. Looks like it stays open for the process which open this data source, even if connection is closed.
maxym_urt at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5
Try also to call Dispose method of the connection and reader after they closed but before they set to null. I believe you culd also explicitly call Collect method of the GC after that
VMazur at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 6
Dispose method doesn't work too.
I don't know about what "Collect" pethod you are talking about. Can you give me any example?
maxym_urt at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 7

Here is desription for the Collect method

http://msdn2.microsoft.com/en-us/library/system.gc.collect.aspx

Do not use it too frequently, because it could affect performance of the application, but it could help in your specific case

VMazur at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified