473,703 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting MDB after creating it, causes "file is in use by another process"

Hi,

Ive got the following code which seems ok but when the user runs the
function for a second time I get an error message stating that the mdb
is in use by another process. There is still an ldb for the life of the
application even after calling oldebconnection .close and gc.collect.

Any ideas?
[Code Starts]
private void btnRecreateData base_Click(obje ct sender,
System.EventArg s e)
{
string mdbFileName = Application.Sta rtupPath + @"\Eve21.mdb ";
// Delete mdb file if already exists
if (System.IO.File .Exists(mdbFile Name))
{
MessageBox.Show ("Deleting MDB");
System.IO.File. Delete(mdbFileN ame);
}

Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

if (objClassType != null)
{
object obj = Activator.Creat eInstance(objCl assType);
// Create mdb file
obj.GetType().I nvokeMember("Cr eate",
System.Reflecti on.BindingFlags .InvokeMethod, null, obj, new
object[]{
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + mdbFileName + ";"
});

if (System.IO.File .Exists(mdbFile Name))
{
using (OleDbConnectio n connection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
mdbFileName
+ ";Persist Security Info=False"))
{
connection.Open ();
if (connection.Sta te == System.Data.Con nectionState.Op en)
{
MessageBox.Show ("Connection closing");
connection.Clos e();
GC.Collect();
}
}
}
}


}
[Code Ends]

Error appears in the
Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

line but I think this is misleading and its being caused by the
file.delete.
Thanks in Advance

Nov 17 '05 #1
3 2992
> is in use by another process. There is still an ldb for the life of the
application even after calling oldebconnection .close and gc.collect.

It helps if you explicitly free all your COM objects with a call to
System.Runtime. InteropServices .Marshal.Releas eComObject.

Greetings,
Wessel
Nov 17 '05 #2
Ok, well you can call GC.Collect until the cows come home, but the fact of
the matter is when you are dealing with a file-based database engine such as
Jet (Access) you are going to have to take extreme care to release all COM
object references and even then, you may still find that IIS has tied up the
file in some way. Suggest you look at alternatives such as MSDE or
preferably, SQL Express (SQL Server 2005) both of which are currently free.
--Peter

<kr********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi,

Ive got the following code which seems ok but when the user runs the
function for a second time I get an error message stating that the mdb
is in use by another process. There is still an ldb for the life of the
application even after calling oldebconnection .close and gc.collect.

Any ideas?
[Code Starts]
private void btnRecreateData base_Click(obje ct sender,
System.EventArg s e)
{
string mdbFileName = Application.Sta rtupPath + @"\Eve21.mdb ";
// Delete mdb file if already exists
if (System.IO.File .Exists(mdbFile Name))
{
MessageBox.Show ("Deleting MDB");
System.IO.File. Delete(mdbFileN ame);
}

Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

if (objClassType != null)
{
object obj = Activator.Creat eInstance(objCl assType);
// Create mdb file
obj.GetType().I nvokeMember("Cr eate",
System.Reflecti on.BindingFlags .InvokeMethod, null, obj, new
object[]{
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + mdbFileName + ";"
});

if (System.IO.File .Exists(mdbFile Name))
{
using (OleDbConnectio n connection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
mdbFileName
+ ";Persist Security Info=False"))
{
connection.Open ();
if (connection.Sta te == System.Data.Con nectionState.Op en)
{
MessageBox.Show ("Connection closing");
connection.Clos e();
GC.Collect();
}
}
}
}


}
[Code Ends]

Error appears in the
Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

line but I think this is misleading and its being caused by the
file.delete.
Thanks in Advance

Nov 17 '05 #3
<kr********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi,

Ive got the following code which seems ok but when the user runs the
function for a second time I get an error message stating that the mdb
is in use by another process. There is still an ldb for the life of the
application even after calling oldebconnection .close and gc.collect.

Any ideas?
[Code Starts]
private void btnRecreateData base_Click(obje ct sender,
System.EventArg s e)
{
string mdbFileName = Application.Sta rtupPath + @"\Eve21.mdb ";
// Delete mdb file if already exists
if (System.IO.File .Exists(mdbFile Name))
{
MessageBox.Show ("Deleting MDB");
System.IO.File. Delete(mdbFileN ame);
}

Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

if (objClassType != null)
{
object obj = Activator.Creat eInstance(objCl assType);
// Create mdb file
obj.GetType().I nvokeMember("Cr eate",
System.Reflecti on.BindingFlags .InvokeMethod, null, obj, new
object[]{
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" + mdbFileName + ";"
});

if (System.IO.File .Exists(mdbFile Name))
{
using (OleDbConnectio n connection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
mdbFileName
+ ";Persist Security Info=False"))
{
connection.Open ();
if (connection.Sta te == System.Data.Con nectionState.Op en)
{
MessageBox.Show ("Connection closing");
connection.Clos e();
GC.Collect();
}
}
}
}


}
[Code Ends]

Error appears in the
Type objClassType = Type.GetTypeFro mProgID("ADOX.C atalog");

line but I think this is misleading and its being caused by the
file.delete.
Thanks in Advance


Perhaps this is a very stupid suggestion, but do you happen to have an
Anti-Virus program? I've had problems creating or copying files and then
trying to delete them because the company anti-virus' "paranoia" settings
are scanning files I'm trying to delete.

Again, this is probably not the problem, but it is something to be aware or.

Good Luck,

Carl
Nov 17 '05 #4

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

Similar topics

9
715
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 anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
4
13245
by: Earth Worm Jim | last post by:
I am using VS.Net 2003 on Windows 2003 Server (standard edition) and I am getting "The process cannot access the file because it is being used by another process" on DLL's in a VS.Net solution. I have made sure all the dependancies and the build order is correct but the actually instance of VS.Net (devenv.exe) is LOCKING THE DAM DLL'S IT IS TRYING TO BUILD. ????? I have used Process Explorer from sysinternals.com to confirm this.
3
4539
by: Daniel Billingsley | last post by:
Today I went to compile a solution I've been working on for months. I've been off most of the last few months, so there's been a gap in the work, but I did compile it a few times earlier this week. Today I get a message: Could not write to output file 'D:\DevelopmentProjects\Enterprise\CustomUtilities\obj\Debug\CustomUtilities ..dll' -- 'The process cannot access the file because it is being used by another process. '
3
3685
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use by another process. This occurs even if I release the object using fs.Close() and fs = Nothing. Please help (my code is given below) Best regards
7
23184
by: RSH | last post by:
Hi, I have an ASP .Net web page that creates a temp directory on the server then it is using the File.Copy command to move a file to a temp download directory, Then I am doing a response.Redirect to that URL. The problem is that whenever I run the page the script fails on the File.Copy() command everytime with an error of: The process cannot access the file
4
4014
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what seems to be the problem. These are video files and are enormous with long crazy names so trying to hand type the file name in a text box is not an option. So I'm using an Input "file" control so when the user browses out onto the network...
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9243
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2057
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.