How to close Database when using JScript

  • Thread starter Thread starter Mike Hixson
  • Start date Start date
M

Mike Hixson

Im using the Windows Installer Automation Interface to do some
post-processing on a .msi file created with InstallShield. Im running
into problem with the Database object not releasing its lock on the
..msi file. I have 2 seperate functions in my JScript that call the
OpenDatabase method on the same .msi file. The second function always
fails, complaining that the file is already open, even though the
first Database object instace is gone (out of scope). My understanding
is that when the Database object instance goes out of scope, the file
lock should be released -- this is how it works with VBScript. I could
consolidate the 2 functions but the lock that is held by the Database
object causes problems in other parts of the script. Does anyone know
how to close the lock that the Database object has?

Here an example that can reproduce the problem. It attempts to open
the same file two consecutive times. The second one always fails
complaining that the file is locked.


ModifyDB(1);
ModifyDB(2);

function ModifyDB(i)
{
var oInstaller = new ActiveXObject("WindowsInstaller.Installer");

var oDatabase = oInstaller.OpenDatabase("c:\\setup.msi", 1);
oDatabase.Commit();

oDatabase = null;

WScript.Echo(i);
}

Regards,
Mike
 
This is happening because java script is based on a the garbage collection
mechanism, and the timing of the collector is indeterminiate. Even calling
CollectGarbage() might not do the job. My suggestion will be to use a global
object variable or use a mix of vbs and js. Just set the object to nothing
in vbs and you will be in good shape.
--

Regards,
Sajan.

PS: Please don't send me direct emails, use the newsroom.
 
Back
Top