How to close Database when using JScript

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
 
K

Kallely Sajan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top