Forum Discussion

artigas's avatar
artigas
Occasional Contributor
12 years ago

The process cannot access the file because it is being used by another process.

Greetings -



Step 1) I copy a file into C:\Temp\maintenance_boxfavorites_add.xls [aqFile.Copy() ]



Step 2) I initiate a data driven loop to import the data into a database table.



Step 3) I delete C:\Temp\maintenance_boxfavorites_add.xls [aqFile.Delete()]



All steps complete in the green. Checking I find that the file has not been deleted. Error message is:

The process cannot access the file because it is being used by another process.

 Path: C:\Temp\maintenance_boxfavorites_add.xls




I attempted to put a delay of 20 seconds to give the data loop entry
process a chance to complete. This delay did not work, I still get the
error.



function DeleteImportFile()

{

    BuiltIn.Delay(20000,"Waiting for last operation to finish");

    aqFile.Delete("C:\\Temp\\maintenance_boxfavorites_add.xls");

//    BuiltIn.Delay(2000,"Waiting for last operation to finish");

}



I have uploaded a picture to show the condition at the end of the test.



Need some suggestions here.

Thanks In Advance

6 Replies

  • ASV's avatar
    ASV
    Contributor
    Hi Roberto

    I think that in your step 2 you have forgotten to close workbooks and quit Excel application.
  • artigas's avatar
    artigas
    Occasional Contributor
    My apologies for my lack of knowledge.



    How exactly do i do that?



    Thanks In Advance
  • ASV's avatar
    ASV
    Contributor
    This code is in VBScript. If you use Sys.OleObject("Excel.Application") write in this way




        Set objExcel = Sys.OleObject("Excel.Application")

        objExcel.Workbooks.Open(strPathExcel)





    .............................................................................





        objExcel.DisplayAlerts = False

        objExcel.ActiveWorkbook.SaveAs(strPathExcel)

        objExcel.Quit

        Set objExcel = Nothing



    If you use DDT.ExcelDriver



       Set excelData = DDT.ExcelDriver(strPathExcel, sheetname)



    ..........................................................................................



      DDT.CloseDriver(excelData.Name)
  • artigas's avatar
    artigas
    Occasional Contributor
    Greetings -



    The answers posted here led me to a solution in jScript.



    function Box_Favorites_02_Add_Script()

    {

      Aliases.p3main707.wndClaWin_PPP_Frame.MainMenu.Click("[1]|[1]");

      Delay(5000, "Box Favorites Browse");

      Project.Variables.BoxFavorites_Add_xls.Reset();

      for(; !Project.Variables.BoxFavorites_Add_xls.IsEOF();)

      {

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites.ClaChildClient.ClaButton_Add.Click(17, 11);

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaEdit_Barcode.Keys(Project.Variables.BoxFavorites_Add_xls.Value("Barcode"));

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaEdit_Description.Keys(Project.Variables.BoxFavorites_Add_xls.Value("Description"));

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaEdit_Length.Keys(Project.Variables.BoxFavorites_Add_xls.Value("Length"));

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaEdit_Width.Keys(Project.Variables.BoxFavorites_Add_xls.Value("Width"));

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaEdit_Height.Keys(Project.Variables.BoxFavorites_Add_xls.Value("Height"));

        Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites_Add.ClaChildClient.ClaButton_OK.Click(28, 10);

        Project.Variables.BoxFavorites_Add_xls.Next();

      }

      Project.Variables.BoxFavorites_Add_xls.Disconnect();

      Aliases.p3main707.wndClaWin_PPP_Frame.MDIClient.wndClaWin_BoxFavorites.ClaChildClient.ClaButton_Close.Click(16, 8);

    }



    The key line that was missing after converting the Keyword Test to script was the *.Disconnect();

  • e_lock's avatar
    e_lock
    Occasional Contributor
    I think this may be a solution to my issue, but I can't get it to work.  I am also trying to delete a file which TC does have access too (it can delete it if I call the delete prior to anything else) but can't once it's been used as a datasource as TC keeps a handle to it.  I initialise the data loop via the GUI, but have tried calling the disconnect as a code snippet and as a function, but can't make it work  Anyone got any ideas please?  I have also tried calling closeDriver on the ddt object but that didn't work either.