cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tcom36
Level 7

SQL Scripts to run only on first time install

I have an InstallScript MSI project with some SQL scripts under the Server Configuration->Sql Scripts view.

Some of these scripts should only be called on the first install. I checked on these scripts the "Run Script During Install", but it gets also called on repair or update.

Is there any way to make them execute only on first install?

I tried to set a property OnFirstUIBefore:

MsiSetProperty(ISMSI_HANDLE, "MYPROJECT_FIRST_INSTALL", "first");

and use it under "Specify a Conditional Statement", but this statement does not seem to be evalutated properly.

Any idea?
Labels (1)
0 Kudos
(10) Replies
Cromagnon35
Level 4

the NOT INSTALLED = "TRUE" condition should work.
0 Kudos
tcom36
Level 7

Seems not to work. Whatever the condition evaluates to in the first install, it seems to keep that value on the maintenance installs.

I have the feeling, the conditions to run the SQL Scripts are not reevaluated during a maintenance/update install.

Is it possible to have the feature conditions reevaluated on maintenance?
0 Kudos
tcom36
Level 7

I tried several other methods, none seem to work.

I have an SQL script createDB.sql belonging to a feature "localDatabase". This script create the whole db schema with tables, users, stored procedures,.... I would like my InstallScript MSI project to call it only on the first install.

I inserted the script under Server Configuration/SQL Scripts. Under runtime, i tried several settings:

[LIST=1]
  • Checked "Run Script During Install" only -> script is called always, on first install, repair, change
  • Checked "Specify a Conditional Statement" only and set as condition: NOT INSTALLED -> script is never called
  • Checked "Specify a Conditional Statement" only and set as condition: (&localDatabase=3) AND NOT (!localDatabase=3) -> script is never called


    Any other idea?
  • 0 Kudos
    hidenori
    Level 17

    Please try "NOT Installed" instead of "NOT INSTALLED". You may also need to set the Reevaluate Condition property to Yes for the associated component of your SQL script. See this thread for more information.
    0 Kudos
    tcom36
    Level 7

    I must do something wrong, I have tried "NOT Installed" but without success, the sql script is never called.

    I have a feature "localDB":
    - Install Level 500
    - Condition to set installlevel to 1.
    - the feature has two components: createDb.sql and dropDb.sql

    Component createDb.sql_SQLComponent:
    - Reevaluate Condition: YES

    Component dropDb.sql_SQLComponent:
    - Reevaluate Condition: YES

    Server Configuration/SQL Scripts/createDb.sql:
    - Runtime: checked only "Specify a Conditional Statement" and NOT Installed as condition

    Server Configuration/SQL Scripts/dropDb.sql:
    - Runtime: checked only "Run Script During Uninstall"

    Why is createDb.sql not called on a first install? Did I miss something?
    0 Kudos
    hidenori
    Level 17

    You probably need to set the Install Level property of the feature below 100, and then elevate it above 100 using the Condition property if you do not want to install the feature for some conditions. I recommend that you check to see if the feature "localDB" is getting installed by generating a Windows Installer verbose log for the installation.
    0 Kudos
    tcom36
    Level 7

    hidenori wrote:
    I recommend that you check to see if the feature "localDB" is getting installed by generating a Windows Installer verbose log for the installation.


    Could you explain a bit more, or point me to page explaining this?

    How do I check if the feature is installed by generation a windows installer verbose log?
    0 Kudos
    hidenori
    Level 17

    You can generate a Windows Installer verbose log for your installation from the command line as follows:

    setup.exe /v"/l*v c:\log.txt"

    And search for the following entry in the log file:

    Feature: localDB; Installed: Absent; Request: Local; Action: Local

    Make sure that the Action state is Local.
    0 Kudos
    RashidYunus
    Level 2

    I am facing similar problem. tom36, can you please confirm if the solution suggested by hidenori helped to resolve your problem. For me it didn't.
    Any other solutions?:mad:
    0 Kudos
    Christopher_Pai
    Level 16

    The property is Installed not INSTALLED.

    Not Installed


    BTW, I find it better to just do inline logic/error handling in your SQL and let the script run whenever the associated feature is being installed/reinstalled/uninstalled. This gives you more flexibility in servicing.
    0 Kudos