Create dynamic shortcut using value from SQL query - Advanced Installer Community
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Create dynamic shortcut using value from SQL query

Been fighting this for most of the day and finally breaking down and posting here. Hopefully someone knows if I'm doing something wrong. For the past several years, our installer always used the built-in Files and Folders -> Desktop screen to create our desktop shortcut. Because of some recent changes to our software, the desktop shortcut location is no longer static and the port number can change based on a setting in a database table.

To solve this, I'm trying to utilize 2 different Custom Actions in our execution: the first is a SQL Query that will get the value out of the table and stick it in a variable, and the second is a Powershell inline script that will create the shortcut. I've tested both of those separately on my local machine, so I know the query syntax and powershell syntax is correct. With the installer, the shortcut gets created, as well as the icon (so I know I'm passing parameters correctly to the inline script), but the port number is always 0. I must be doing something wrong. I'll attach some screencaps of my SQL Query and 2 custom actions. Thanks in advance.

SQL Query
SQL Query.png
SQL Query.png (65.08 KiB) Viewed 20351 times
SQL Query Custom Action
SQL Query Custom Action.png
SQL Query Custom Action.png (60.72 KiB) Viewed 20357 times
Powershell shortcut create Custom Action
Powershell Custom Action.png
Powershell Custom Action.png (78.09 KiB) Viewed 20357 times
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello and welcome to Advanced Installer forums,

Unfortunately, I can not say for sure why this happens.

In order for me to further investigate this issue, could you please create a verbose log of the installation process and forward that to me, either here or by e-mail at support at advancedinstaller dot com?

Also, if possible, could you please also send me a copy of your .AIP file so I can investigate its settings?

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Thanks for the reply, I'm emailing you now. Subjuct line will be the same as the post title.
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Did you receive my email on Friday?
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello Chris,

Yes, I have received your e-mail.

This is currently under my investigations.

Once I will have a conclusive answer, I will followup on this thread.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello Chris,

Thank you for your patience on this and for the provided files.

I have further investigated this and I found the culprit. Both your PowerShell script and the SQL Query are correct (syntax and logic wise). However, the problem here is that the custom action that executes your SQL Query is skipped (does not execute):

Portion taken from the log generated with a test project:
MSI (s) (A4:88) [17:07:59:236]: Doing action: SqlQueryAction
Action 17:07:59: SqlQueryAction.
Action start 17:07:59: SqlQueryAction.
MSI (s) (A4:88) [17:07:59:246]: Skipping action due to msidbCustomActionTypeFirstSequence option.
Action ended 17:07:59: SqlQueryAction. Return value 0.
What I would like you to notice here is the msidbCustomActionTypeFirstSequence flag. Basically, this flag is similar to the following option in Advanced Installer:

"Custom Actions" page --> the custom action that executes your query --> under "Execution Stage Condition" --> "Advanced execution scenarios ..." hyperlink --> "Skip action in Install Execution Stage if executed in Dialogs Stage".

If you clicked on the hyperlink I've earlier given, you can notice that it states that:
Execute no more than once if present in both sequence tables. Always skips action in execute sequence if UI sequence has run. No effect in UI sequence. The action is not required to be present or run in the UI sequence to be skipped in the execute sequence. Not affected by install service registration.
With that being said, this is the reason why your custom action is skipped. In order to execute it, please click on the "Advanced Execution Scenarios ..." hyperlink and check the "Always execute" radio button.

Quick note: when adding an SQL Query in Advanced Installer, the custom action that executes this query is added automatically in the Custom Actions page. By default, this custom action is added as shared between the two stages ("Wizard Dialogs Stage" and "Install Execution Stage"), therefore the "Skip action in Install Execution Stage if executed in Dialogs Stage" is selected by default. However, if one of the custom actions is deleted (e.g. the one from the "Wizard Dialogs Page"), by my logic, the option should be changed automatically to "Always Execute". However, we do not currently do this and this is, as you can see, causing some troubles. An improvement request has already been made in this regard and hopefully it will be implemented in a future version of Advanced Installer.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Catalin,

Thank you for the reply and explanation. I've done what you recommended (changed the Query Custom Action to Always Execute), however, it's still not working. In the installer log, I'm outputting system variables at several points during the execution of the installer, and ADMIN_PORT is always 0. Then, towards the bottom of the install.txt log (line 14903), this line appears:
MSI (s) (14!28) [14:45:06:933]: PROPERTY CHANGE: Deleting ADMIN_PORT property. Its current value is '0'.

So, perhaps there is still something wrong with the aip structure. May I e-mail you my aip file and install log again for you to take a look?
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello Chris,

Well, this is strange.

If you only changed the option I've suggested, then please send me only the installation log file. If you have changed something else in the .AIP file beside the option I've suggested, then yes, please send me the .AIP file as well.

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Thanks, I just sent you another email with further information.
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello Chris,

Thank you for your sent files.

I've had a look over the sent log file and the .AIP file and, upon further investigations, I came to the conclusion that your SQL Query does not return anything. Basically, it returns an empty result set ==> the property is set to empty string, which basically means the deletion of the property. A property can have two states:

- it has a value, therefore it exists

- it has no value, therefore it does not exist

This is the reason why you have seen the deletion of your property in the log file.

If the query is successful, the property will correctly be set. For instance, for a database that looks like this:
DB.png
DB.png (4.86 KiB) Viewed 20254 times

a query such as:

Code: Select all

SELECT FirstName FROM Persons WHERE PersonID = 123
is correctly returning "Catalin". I have changed the "PersonID" value to "1234" (without quotes) (basically, a value that does not exist in my database) and what is happening is the property that stores the value of the query is empty, therefore the property is deleted (according to the log file. Also, I have placed a MessageBox custom action right after the SQL Query executes which should print the value of the property, and it returned empty string).

Few things I would suggest here:

1. make sure that the query properly works outside of Advanced Installer

2. make sure that you connected successfully to the SQL Server. I would suggest using our predefined "SQL Server Connection" dialog, which will automatically configure everything for you (server browse, database browse, etc.).

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Thank you for the response. We have a SQL connection set up, as we are executing a few other scripts during the install as well. My next question would be at what stage of an install do the SQL scripts get executed? Perhaps when my GetAdminPort query runs, the value is not yet in the database? See these screenshots. You can see the GetAdminPort querying the Settings table for the 'Value' where Application = 7 and Name = 'HttpPort'. Then in the next screenshot you can see that the record is being inserted into the table. But, if that UpgradeAllVersionsTo5.3.0 script is running after the query, then that would make sense why it's deleting the value. I'm just not sure where to stick the query I guess.
2019-12-23 08_37_19-Window.png
2019-12-23 08_37_19-Window.png (57.13 KiB) Viewed 20232 times
2019-12-23 08_38_38-Window.png
2019-12-23 08_38_38-Window.png (85.95 KiB) Viewed 20232 times
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Any update to my last reply?
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

Hello Chris,

First of all, please accept my apologies for the delayed reply. We had some days off due to holidays and New Year's Eve, so I did not have time to come back to you. I apologize for that.

I remember investigating the content of all your scripts but I did not see where you have set those fields. Most probably, you have sent me an older version of the .AIP file, otherwise I should've notice it.

Please allow me to explain this. The main difference between a Script and a Query (Advanced Installer wise) is the fact that a script is executed only during the deferred stage of the installation, while a query can be executed during all stages (immediate, deferred, etc.). As you may know, the immediate stage executes before the deferred stage, meaning that your query is executed before the script that actually updates the database. With that being said, that is the reason why your query never returns anything.

In order to fix that, please go to "Custom Actions" page --> select your custom action and set its "Execution Time" to "When the system is being modified (deferred)". This way, your query will be executed after the script which inserts the values into the database, therefore it should return the expected values.

Hope this helps.

Best regards,
Catlain
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
cjens19
Posts: 8
Joined: Thu Dec 12, 2019 9:35 pm

Re: Create dynamic shortcut using value from SQL query

Sorry for the delay, I just now am getting back to looking at this. Your latest steps worked (Changing to deferred) and I'm now able to query the value from the database! Thank you for your persistence in helping us get around this.

Cheers!
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Create dynamic shortcut using value from SQL query

You are always welcome, Chris.

I am really glad I could help and it is my pleasure to do so.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”