How to install SQL Server Express with your application
The 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.
Starting 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.
SQL Server Express 2016, 2017 and 2019 is no longer supported on
x86 processors. Therefore, Microsoft offers only the 64 bit installer.
Select “Files
and Folders” -> Local Application Data from
the “Resources” group on the left pane.
Click on the 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).
Go 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
Go to Custom Actions page from the
“Custom Behavior” group on the left
pane.
Select Launch
file custom action, click on 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
Go to Search Page page from the
“Custom Behavior” group on the left
menu.
Click the SQLEXPR_2012_X86_VERSION.
button and set the property name to Use the
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
You 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
Go 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.
If 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.
For 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).