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

Call SQL-Script only if DB engine installed

Hello

I am writing a InstallScript MSI for a software which can use a local SQLExpress DB, but also a remote database.

I have added SQLExpress as prerequisite which the user can choose to not install.

I defined a feature to install the SQL scripts to generate the schema, and call them within the "SQL Script" view. Is there any way to only execute these SQL-Scripts when SQLExpress is installed?

I though I could use the "Conditional Statement Builder" for this feature to check if I find the relevant entry of the DB in the registry, but I have no clue how to check for a registery entry there.

Any idea how I can make the calling of these SQL-Scripts dependent on the presence of the local DB?

Thank you in advance.
Labels (1)
0 Kudos
(6) Replies
RobertDickau
Flexera Alumni

You could use the System Search Wizard to read the registry information and store it in a property that you could then use in a condition; or else you could use RegDBSetDefaultRoot and RegDBKeyExist to see if the information is there, and then similarly use MsiSetProperty to create a property that you can then use in a condition.
0 Kudos
tcom36
Level 7

I tried it with the condition, but I guess I made something wrong, as InstallShield always wants to build up connection with the SQLServer even when no SQLServer is present.

Under System Search, I defined a search for a regKey:
Registry Root: HKEY_LOCAL_MACHINE
Registry Key: SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\Setup
Registry Value: SQLPath
stored as property IS_DB_PRESENT

Under Setup Design, I have a feature localDB:
Install Level: 0
Condition: Level 1 Condition IS_DB_PRESENT >< "MSSQL"

Am I right, localDB is normally not installed, except when IS_DB_PRESENT contains MSSQL?

At the moment, I am not sure if it works, it tries nevertheless OnSQLLogin.
0 Kudos
hidenori
Level 17

You also need to add a code to the beginnig of OnSQLLogin() that will return the event immediately when the IS_DB_PRESENT property does not contain MSSQL.
0 Kudos
tcom36
Level 7

Problem solved.

The OnFirstUIBefore() calls OnSQLLogin which tries to connect to the database, even if no database engine is present.

I added a method checking the created property IS_DB_PRESENT above to make sure the database is present before calling OnSQLLogin.

Now, I call OnSQLLogin and install the localDB feature only when the database engine is present.

Thank you for your help Robert.

Now I need to find out in which directory Excel is installed to add an excel macro...
0 Kudos
ISNewone
Level 3

Your method will work for local DB only.

There is no way the registry key will tell you if a remote DB was installed.
0 Kudos
tcom36
Level 7

ISNewone wrote:
Your method will work for local DB only.

There is no way the registry key will tell you if a remote DB was installed.


That is right and also intended that way. The application supports a local SQLExpress database and provide the needed stuff in the installer to support it.

The application also supports remoteDB (but SQLExpress, Oracle and MySQL). Configuring and installing these databases are not part of the installer. The application will use them if configured properly.
0 Kudos