Closing Access file created with ADOX.CatalogClass

V

VMI

I'm creating an Access file with the following code, but won't let me erase
it after creating it. How can I close the file immediately after creating
it?

ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + sFileName + ";" +
"Jet OLEDB:Engine Type=5");
cat=null; // Does NOT work



Thanks.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Try this:

Marshal.ReleaseComObject(cat);
cat = null;
GC.Collect(); // This is the last resort - don't use if ReleaseComObject
alone helps.
 
V

VMI

It worked. Thanks.


Dmitriy Lapshin said:
Hi,

Try this:

Marshal.ReleaseComObject(cat);
cat = null;
GC.Collect(); // This is the last resort - don't use if ReleaseComObject
alone helps.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

VMI said:
I'm creating an Access file with the following code, but won't let me
erase it after creating it. How can I close the file immediately after
creating it?

ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + sFileName + ";" +
"Jet OLEDB:Engine Type=5");
cat=null; // Does NOT work



Thanks.
 
Joined
Jun 15, 2005
Messages
1
Reaction score
0
Release and unlock an Access database file (.mdb) created using ADOX

VMI said:
I'm creating an Access file with the following code, but won't let me erase
it after creating it. How can I close the file immediately after creating
it?
When you create the database, a connection is created to the database automatically. You must close the connection to release the lock on the file. The connection is in the catalog's ActiveConnection property.

Using COM references:
1) Microsoft ActiveX Data Objects 2.8 Library
2) Microsoft ADO Ext. 2.8 for DDL and Security

Sample code:

private void CreateDatabaseFile(string filename)
{
ADOX.CatalogClass catalog = new ADOX.CatalogClass();
catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Jet OLEDB:Engine Type=5");

ADODB.Connection connection = catalog.ActiveConnection as ADODB.Connection;
if (connection != null)
{
connection.Close();
}
catalog.ActiveConnection = null;
catalog = null;
}
 
Last edited:
Joined
Apr 10, 2006
Messages
1
Reaction score
0
I have the some problem but this solution doesn't work for me. I want to destroy database that i create but i can't. I get this exception:

Additional information: The process cannot access the file "C:/.../vIP." because it is being used by another process.

The code that I use is:

*****************************************************
ADOX.CatalogClass catalog = new ADOX.CatalogClass();


catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +

"Data Source=C:/.../vIP.;" + "Jet OLEDB:Engine Type=5");


System.Runtime.InteropServices.Marshal.ReleaseComObject(catalog);

catalog =
null;

GC.Collect();



System.IO.File.Delete("C:/.../vIP.");

******************************************************

I now that this problem cause ADOX.CatalogClass catalog because without it, it works, but in that case I create database manual and this is not good choice for me.

Please help. Thanks.
 
Joined
Nov 30, 2007
Messages
1
Reaction score
0
haggy did you got the solution to destroy database

hi,

did you got the solution to destroy database.

if so, please reply!

Thanks
 
Joined
Mar 16, 2013
Messages
1
Reaction score
0
I'm creating an Access file with the following code, but won't let me erase
it after creating it. How can I close the file immediately after creating
it?

ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + sFileName + ";" +
"Jet OLEDB:Engine Type=5");
cat=null; // Does NOT work



Thanks.

I recently experienced this problem.If your development machine is 32 bit while production machine is 64 bit then following code may just save your day!
if (IntPtr.Size == 8)//if the os is 64 bit
{
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=E:\\new folder\\yourfilename.mdb;" +
"Jet OLEDB:Engine Type=5");
cat = null;
}
else
{
if (IntPtr.Size == 4)//if the os is 32 bit
{
ADOX.CatalogClass cat = new ADOX.CatalogClass();
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=E:\\new folder\\yourfilename.mdb;" +
"Jet OLEDB:Engine Type=5");
cat = null;
}
 

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