jmace
Posts: 55
Joined: Thu Jul 01, 2010 4:46 pm

Return Value from Database Server

AI,

How would I go about getting a single value from a database table and putting it in the installer's session so I can install some pieces they stuff that value's condition? I am already collecting all of that connection string information from a form/dialogue.

Thanks,
Jim
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Return Value from Database Server

Hi Jim,

Unfortunately there is no predefined support to get the return value of a SQL Script. This behavior can not be implemented, as the custom action running the sql script is running deferred, thus can not set properties.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jmace
Posts: 55
Joined: Thu Jul 01, 2010 4:46 pm

Re: Return Value from Database Server

I created this sub procedure in VBScript that successfully grabs the database version from an existing installation as follows:

Code: Select all

Public Sub GetCurrentSystemVersion ()
	Dim strServer 
	strServer = Session.Property ("SERVER_ADDRESS")
	Dim strUsername 
	strUsername = "username"
	Dim strPassword
	strPassword = "password"
	Dim strDatabase
	strDatabase = "database"
	Dim strSQL
	strSQL = "SELECT system_version FROM tbl_system"
	Dim strConnect
	strConnect = "Provider=SQLNCLI;Server=" & strServer & ";Database=" & strDatabase & ";Uid=" & strUsername & "; Pwd=" & strPassword & ";"

	Set con = CreateObject("ADODB.Connection")
	Set rs = CreateObject ("ADODB.Recordset")

	con.Open strConnect
	rs.Open strSQL, con

	Session.Property ("CURRENT_SYSTEM_VERSION") = rs.GetString ()

	rs.Close
	con.Close

	Set rs = Nothing
	Set con = Nothing
End Sub
I created a Installation Parameter called CURRENT_SYSTEM_VERSION. I need this sub procedure to be executed when the installation first fires up. As you can see, it assigns CURRENT_SYSTEM_VERSION the result of the SQL statement. I will then use that value, conditionally, to execute specific SQL scripts. How do I go about getting this to execute?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Return Value from Database Server

Hello,

You can execute the .VBS as an Attached Custom Action in the Custom Actions page.
Also, since you are setting an installer property please keep in mind this custom action must be set with immediate execution option.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jmace
Posts: 55
Joined: Thu Jul 01, 2010 4:46 pm

Re: Return Value from Database Server

Can I create this as a UI Custom Action so I can have it fire on a button click or some other predefined event of a dialogue box? This way, on the next dialog, In the sequence or otherwise, I can do specific things on an expression/check of a property assigned by the vbs?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Return Value from Database Server

Hello,
Can I create this as a UI Custom Action so I can have it fire on a button click or some other predefined event of a dialogue box?
Yes, you can add an attached custom action as an UI custom action as well.

UI custom actions have an "Immediate" execution and have access to installer properties whereas custom actions set with "Deferred" execution do not.
Deferred custom actions can receive information about the installation process, mostly only embedded in the CustomActionData property.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”