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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gracepaul
    New Member
    • Jul 2008
    • 28

    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
    Code:
    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
    --------------
    Code:
    Protected Sub btnZip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnZip.Click
            MultipleFileUploadForm.Visible = False
            Dim fz As New FastZip
            fz.CreateZip(Server.MapPath("Hrm123.zip"), Server.MapPath("MTNMRN1/MTNMRN2"), True, "", "")
    
            ResultMsg.Visible = True
            ResultMsg.Text = "The zipping operation completed successfully"
        End Sub

    for unzipping
    -----------------
    Code:
    Protected Sub btnUnzip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUnzip.Click
            MultipleFileUploadForm.Visible = False
            Dim fz As New FastZip
            fz.ExtractZip(Server.MapPath("MTNMRN1/Hrm123.zip"), Server.MapPath("MTNMRN1/MTNMRN2"), "")
            ResultMsg.Visible = True
            ResultMsg.Text = "The files extracted successfully"
        End Sub

    please help
    thanks in advance
    Grace
    Last edited by Curtis Rutland; Oct 14 '08, 01:32 PM. Reason: use [CODE] [/CODE] tags for code
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    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.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        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...catc h" 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.

        Comment

        Working...