470,614 Members | 1,548 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Err: The process cannot access the file,because it is being used by another process

hi,
i got an exception while i m trying to zip/unzip a database inside the serverfolder
Expand|Select|Wrap|Line Numbers
  1. System.IO.IOException: The process cannot access the file 'E:\hshome\holsoftsystems\indusmotor.co.in\MTNMRN1\MTNMRN1\MTNMRN2\Hrm123.ldb' because it is being used by another process.
the database is being used by another process.
i have to zip this database and download it provided it can be used by another process.

how can i do this
i use the following code for zipping/unzipping


for zipping
--------------
Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnZip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnZip.Click
  2.         MultipleFileUploadForm.Visible = False
  3.         Dim fz As New FastZip
  4.         fz.CreateZip(Server.MapPath("Hrm123.zip"), Server.MapPath("MTNMRN1/MTNMRN2"), True, "", "")
  5.  
  6.         ResultMsg.Visible = True
  7.         ResultMsg.Text = "The zipping operation completed successfully"
  8.     End Sub

for unzipping
-----------------
Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnUnzip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUnzip.Click
  2.         MultipleFileUploadForm.Visible = False
  3.         Dim fz As New FastZip
  4.         fz.ExtractZip(Server.MapPath("MTNMRN1/Hrm123.zip"), Server.MapPath("MTNMRN1/MTNMRN2"), "")
  5.         ResultMsg.Visible = True
  6.         ResultMsg.Text = "The files extracted successfully"
  7.     End Sub

please help
thanks in advance
Grace
Oct 14 '08 #1
3 3174
kenobewan
4,871 Expert 4TB
The most common reason for this is that the file is being used by the database. You can only perform operations on DB file that are no longer in use.
Oct 14 '08 #2
Frinavale
9,735 Expert Mod 8TB
Make sure you clean up your resources after you use them: close any connections to the file after your finished with it...otherwise the file will still be accessed by your application even after it is finished with it.

-Frinny
Oct 14 '08 #3
tlhintoq
3,525 Expert 2GB
Its also good practice to not assume you have access to files/objects. You can never assume that the PC is the private playground of only your application, or that every file on it is in pristine condition. Something else may have a file tied up, or a file can be corrupted.

Here there is no checking to see if the file is in use before you try to access it, nor is your attempt to access it surrounded by a "try...catch" block (or the VB equivilent to this C# construct).

I'm not sure if there is a 'better" way to see if a file is already in use but...
I usually make an effort to rename the file, adding an underscore to the start of the file. If I get an exception in trying to rename it then I know its in use and I don't even bother to try to open. If the file is successfully renamed, then I can *try* to open, plus I know my other functions ignore any file that starts with an underscore. But that's just my scheme. I'm sure a dozen more seasoned experts will come back with "why don't you just do x,y,z", which I would personally love to see other ways of doing it.
Oct 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.