How to install SQL Server Express with your application

ImportantThe following article uses options that are available starting with the Professional edition and project type.

MSSQL Server 2008R2 SP2 (or later) cannot be installed from your MSI package as a feature-based or post-install prerequisite. Because the MSSQL Server setup is blocked as long as any other MSI is open for installation, the only options are to launch the MSSQL Server installation before or after the MSI's run.

ImportantStarting with SQL Server 2012 R2 you can include its setup package in your main installation package as a feature-based prerequisite. For details, please check the install SQL as feature-based prerequisite FAQ.

If you wish to run MSSQL Server setup before your MSI launch, select SQLEXPR from our list of predefined Prerequisites. Keep in mind that the EXE bootstrapper is required for the Pre-install prerequisites functionality to work.

In this article is presented a solution to (conditionally) run MSSQL Server setup from your MSI (after finish). However, this solution is more complicated and reduced in functionality than one-click configuration via predefined Prerequisites, but it allows embedding MSSQL Server setup within your application's MSI package instead of an EXE package.

1. Add SQLEXPR setup files

The goal is to install the x86 package on 32-bit systems and the x64 package on 64-bit systems. For this article, we'll use the setup files for MSSQL Server Express 2012. However, the same procedure can be applied to MSSQL Server 2008R2 SP2 or 2014.

NoteSQL Server Express 2016, 2017 and 2019 is no longer supported on x86 processors. Therefore, Microsoft offers only the 64 bit installer.

Files and FoldersSelect “Files and Folders” -> Local Application Data from the “Resources” group on the left pane.

Add filesClick on the [ Add Files ] toolbar button and select SQLEXPR setup files for both architectures (x64 and x86).

2. Tweak conditions for deployment

We don't need both setup files to be extracted on all systems. Instead, we want to extract only the corresponding SQLEXPR setup file for the target architecture (x64 or x86).

OrganizationGo to Organization page from the “Deployment” group on the left pane.

Select SQLEXPR_2012_x64_ENU.exe component and add the condition "Application is being installed on a 64-bit operating system" (VersionNT64). You can also enable the "64-bit component" attribute.

Select SQLEXPR_2012_x86_ENU.exe component and add the condition "Application is being installed on a 32-bit operating system" (NOT VersionNT64).

3. Add custom actions that will trigger the installation

Custom ActionsGo to Custom Actions page from the “Custom Behavior” group on the left pane.

Add custom action with sequence Select Launch file custom action, click on [ Add a custom action with a sequence ] button and move it after the "Finish Execution" action group from "Install Execution Stage". Rename it to LaunchFile_x86 and edit these fields:

  • File to Launch: [#SQLEXPR_2012_x86_ENU.exe]
  • Enable "Run as Administrator"
  • Disable all "Wait.." flags from Execution Options group
  • Enable only the "Install" option from the "Execution Stage Condition" group
  • Add condition "Application is being installed on a 32-bit operating system" (NOT VersionNT64)

Repeat the above instructions to create LaunchFile_x64 custom action and edit these fields:

  • File to Launch: [#SQLEXPR_2012_x64_ENU.exe]
  • Enable "Run as Administrator"
  • Enable "Use 64-bit Launcher"
  • Disable all "Wait.." flags from Execution Options group
  • Enable only the "Install" option from the "Execution Stage Condition" group
  • Add condition "Application is being installed on a 64-bit operating system" (VersionNT64)

4. Check if MSSQL Server is already installed

SearchGo to Search Page page from the “Custom Behavior” group on the left menu.

Click the [ Search ] button and set the property name to SQLEXPR_2012_X86_VERSION.

Import REG file Use the [ Registry ] button from the “Search Location” toolbar to create a registry search using these settings:

  • Root: HKEY_LOCAL_MACHINE
  • Key: SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\ClientSetup\CurrentVersion
  • Value: CurrentVersion
  • Type: Retrieve the raw value

TipYou can easily find the Install Conditions of other MSSQL Server versions from their corresponding Advanced Installer Predefined Prerequisites.

Repeat the above instructions to create SQLEXPR_2012_X64_VERSION registry search with the same settings, but enable "Search the 64-bit portion of the registry".

5. Skip launch if MSSQL Server is already installed

Custom ActionsGo back to Custom Actions page from the “Custom Behavior” group on the left pane.

From “Existing Custom Actions” pane, select LaunchFile_x86 and edit the install condition:

(NOT VersionNT64) AND (SQLEXPR_2012_X86_VERSION < "11.0.2100.60")

Finally, select LaunchFile_x64 and edit the install condition:

(VersionNT64) AND (SQLEXPR_2012_X64_VERSION < "11.0.2100.60")

6. Optional configurations

Instead of always launching the corresponding MSSQL Server setup, one can add more install conditions. One common design is to install SQLEXPR if some feature is selected for installation or on a button push. Note that both approaches use custom actions without sequence.

Instead of an interactive installation of MSSQL Server, one can perform a silent install by adding the required parameters into Command field of both Launch file custom actions.

ImportantIf you are installing SQL Server as a prerequisite, you can use the command-line parameter SkipInstallerRunCheck, to avoid the Windows Installer handle check of it.

ImportantFor any questions you can download a small Advanced Installer sample project implementing the solution presented in this howto (SQLEXPR setup files must be placed in the same folder with the sample project file).

7. Video tutorial