Hi all,

I've been searching the net for a solution to this one, but can't get anything to work - not that I found many related posts.

I have an installer database that I copy, edit a property in that copy, and then wish to move to another location.  All appears good until I attempt to move the modified file.  Its still in use. ??

Here's my code...


Dim oInstaller As WindowsInstaller.Installer

Dim oDb As WindowsInstaller.Database

Dim oView As WindowsInstaller.View = Nothing

Try

    oInstaller = CType(CreateObject("WindowsInstaller.Installer"), WindowsInstaller.Installer)

    oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller" & c.Tag & ".msi", 1)

    oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER

    oView.Execute()

    oDb.Commit()

 

 

Catch ex As Exception

    MessageBox.Show(ex.Message)

Finally

    If Not oView Is Nothing Then

        oView.Close()

    End If

    oDb = Nothing

    oView = Nothing

    oInstaller = Nothing

End Try


Is there some other closing statement of some sort I need to utilize.  I've seen a post indicating that the Finally block should take care of it, but no go.

This whole thing is wrapped in a loop that cycles through some text boxes that holds the value of the Property (C.Text), referenced by the controls tag and used in the file name, C.Tag.

Thanks in advance for any feedback!!

1 Comment   [ + ] Show Comment

Comments

  • oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER


    Should be

    oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'")

    Hope this is typo
Please log in to comment

Answers

0
Try adding the .Dispose method after the .Close statement.

Note that every view must be closed in order to avoid leaving open handles.

Personally, I'd be creating a transform rather than messing with MSIs in this way.
Answered 08/20/2015 by: VBScab
Red Belt

Please log in to comment
0
Or use the Session.Database method to directly update the tables on the fly.
Answered 08/20/2015 by: EdT
Red Belt

Please log in to comment
0
You have to set the object to nothing and inform the .NET garbage collection to collect any objects no longer in use (set to nothing). 

For Example:

oInstaller = Nothing
System.GC.Collect()
Answered 08/20/2015 by: jagadeish
Red Belt

Please log in to comment
0

The .Dispose method does not appear to be available to me.

Session method won't work as I'm not doing this at actual install time.

Garbage collection didn't work either.

Answered 08/20/2015 by: Superfreak3
Black Belt

  • Can you move "end try" 3 steps up and then try with System.GC.Collect() at the end
Please log in to comment
0
Maybe my memory's failing me...perhaps it's the database object that needs to have the .Dispose method applied...
Answered 08/20/2015 by: VBScab
Red Belt

Please log in to comment
0

GC still not working for me and I don't get the .dispose method on the database object as well.

Maybe I should re-paste my current code as its changed a bit.  There's a bunch of stuff commented out and the Marshal statements still are in operation.

Is there any harm in using the Marshal statements as they seem to be working.


Dim oInstaller As WindowsInstaller.Installer

Dim oDb As WindowsInstaller.Database

Dim oView As WindowsInstaller.View = Nothing

oInstaller = CType(CreateObject("WindowsInstaller.Installer"), WindowsInstaller.Installer)

oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller_" & c.Tag & ".msi", 1)

oView = oDb.OpenView("UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'")

 

 

oView.Execute()

oDb.Commit()

 

' The following needed for proper file closure

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oView)

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oDb)

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oInstaller)

''Close Not needed due to Marshal above

'If Not oView Is Nothing Then

' oView.Close()

'End If

'' Not sure if this needed any longer...

'oView = Nothing

'oDb = Nothing

'oInstaller = Nothing

'System.GC.Collect()

Answered 08/20/2015 by: Superfreak3
Black Belt

Please log in to comment
0
Can you try with this


    Dim oInstaller As WindowsInstaller.Installer
    Dim oDb As WindowsInstaller.Database
    Dim oView As WindowsInstaller.View = Nothing
    Try
        oInstaller = CType(CreateObject("WindowsInstaller.Installer"),WindowsInstaller.Installer)
        oDb = oInstaller.OpenDatabase(strSourcePath & "\MyInstaller_" & c.Tag & ".msi", 1)
        sSQL = "UPDATE `Property` SET `Property`.`Value`='" & c.Text & "' where `Property`='APP_NETWORK_FOLDER'"

        oView = oDb.OpenView(sSQL)
        oView.Execute()
oDb.Commit()
    Catch ex As Exception
MessageBox.Show(ex.Message)
    Finally
        If Not (oView Is Nothing) Then
            oView.Close()
        End If
        oView = Nothing
        oDb = Nothing
        oInstaller = Nothing
    End Try
Answered 08/21/2015 by: jagadeish
Red Belt

Please log in to comment
0
Nope!  Same Error!!
Answered 08/21/2015 by: Superfreak3
Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity