PC Review


Reply
Thread Tools Rate Thread

How to close Database when using JScript

 
 
Mike Hixson
Guest
Posts: n/a
 
      9th Dec 2003
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
 
Reply With Quote
 
 
 
 
Kallely Sajan
Guest
Posts: n/a
 
      9th Dec 2003
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.

"Mike Hixson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Excel data to database causing Database to Close. Hotwheelsrc51 Microsoft Access External Data 1 17th Jun 2008 04:48 PM
access opens database first time, close and retry database won't o =?Utf-8?B?Y29tcHVzZXIxMA==?= Microsoft Access 2 30th Jan 2007 04:19 PM
What is Server-Side Jscript (not Jscript.NET)? Maxwell2006 Microsoft ASP .NET 5 7th Mar 2006 05:28 AM
Porting from JScript to JScript.Net - compiler error Jon Maz Microsoft ASP .NET 4 9th Sep 2004 11:24 AM
Issue when opening a blank database from JScript Lieven Roelens Microsoft Access Security 1 26th Sep 2003 10:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.