PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.

Closing Access file created with ADOX.CatalogClass

 
 
VMI
Guest
Posts: n/a
 
      13th Jan 2005
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.



 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      14th Jan 2005
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" <(E-Mail Removed)> wrote in message
news:Oi1wVWZ%(E-Mail Removed)...
> 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.
>
>
>


 
Reply With Quote
 
 
 
 
VMI
Guest
Posts: n/a
 
      14th Jan 2005
It worked. Thanks.


"Dmitriy Lapshin [C# / .NET MVP]" <(E-Mail Removed)> wrote
in message news:%231DRk9i%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:Oi1wVWZ%(E-Mail Removed)...
>> 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.
>>
>>
>>

>



 
Reply With Quote
 
New Member
Join Date: Jun 2005
Posts: 1
 
      15th Jun 2005
Quote:
Originally Posted by 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?
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 by FishDawg; 15th Jun 2005 at 12:18 AM..
 
Reply With Quote
 
New Member
Join Date: Apr 2006
Posts: 1
 
      11th Apr 2006
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.
 
Reply With Quote
 
New Member
Join Date: Nov 2007
Posts: 1
 
      30th Nov 2007
hi,

did you got the solution to destroy database.

if so, please reply!

Thanks
 
Reply With Quote
 
New Member
Join Date: Mar 2013
Posts: 1
 
      16th Mar 2013
Quote:
Originally Posted by VMI View Post
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;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aspnet.mdf file still is created even though i created a custom provider? Sunfire Microsoft ASP .NET 1 10th Nov 2007 05:30 AM
Definitions of created, modified and date created in file properti =?Utf-8?B?Wm9kZHk=?= Windows XP General 0 22nd May 2006 08:31 PM
Closing event in a MID Child form I don't know if the child form is closing or the main form is closing **Developer** Microsoft C# .NET 1 19th Oct 2005 04:51 PM
a presentation created on a xp workstation is larger than the exact same presentation created on an nt4 workstation? =?Utf-8?B?amFxX2Zyb3N0?= Microsoft Powerpoint 1 12th May 2004 05:23 AM
Shared border created in FP 2003 and adding to the pages created in FP 98 =?Utf-8?B?TXIuIFNoYWg=?= Microsoft Frontpage 4 9th Jan 2004 11:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 AM.