473,395 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Closing Access file created with ADOX.CatalogClass

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.

Nov 16 '05 #1
3 7612
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" <vo******@yahoo.com> wrote in message
news:Oi****************@TK2MSFTNGP09.phx.gbl...
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.


Nov 16 '05 #2
VMI
It worked. Thanks.
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2*****************@tk2msftngp13.phx.gbl...
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" <vo******@yahoo.com> wrote in message
news:Oi****************@TK2MSFTNGP09.phx.gbl...
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.

Nov 16 '05 #3

When you create the database, a connection is created to the databas
automatically. You must close the connection to release the lock on th
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;D ata Source="
filename + ";Jet OLEDB:Engine Type=5");

ADODB.Connection connection = catalog.ActiveConnection a
ADODB.Connection;
if (connection != null)
{
connection.Close();
}
catalog.ActiveConnection = null;
catalog = null;
}
VMI Wrote:
I'm creating an Access file with the following code, but won't let m
erase
it after creating it. How can I close the file immediately afte
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


--
FishDawgPosted from http://www.pcreview.co.uk/ newsgroup acces

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
1
by: Daniel | last post by:
when writing out a file from .net, when is the file created? after the bytes are all written to the hard drive or before the bytes are written to the hard drive?
0
by: Marc | last post by:
I have a Vb 6.0 project The VB 6.0 project with a just a click of the button...exports the calender rows from OUtlook to a MS Access file ( a DB and a table with the calender rows are created)...
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
0
by: swatijogdand | last post by:
Hi..... Again, it's really very urgent. does nebody have the code for connecting a SQL Server table to an access database using ADOX ??? Thanx in adavance, Regards, Swati
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
6
by: Steven D'Aprano | last post by:
Closing a file can (I believe) raise an exception. Is that documented anywhere? I've spent a lot of frustrating time trying to track this down, with no luck, which suggests that either my...
0
by: rehman | last post by:
Hi, I added reference to COM Component Microsoft ADO Ext. 2.8 for DDL and Security which added a wrapper DLL Interop.ADOX.dll in project references in a web application to create MS Access...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.