Install SQL Server (Express) with your Application
Posted by Guardian in .Net SQL Visual Studio on Thursday 29 January 2009 at 1:32 PM
During the last days I had to put my hands on an hold project written for .NET Framework 1.1 and convert his database from Access to SQL Express 2005, the conversion was quite easy but then the deployment phase stepped in.
We had the requirement of allowing the deployment of the database engine along with the application (ClickOnce is not an option in VS.2003 :D), the Setup project that comes along with VS 2003 rely on merge modules to install external components, but unfortunately no merge module exists for SQL Express (they have been deprecated). So I started looking around for a solution and I came to this msdn article: Embedding SQL Server Express into Custom Applications.
Basically they suggest to write down a wrapper around the installation of the two components (SQL Express and the application) and launch the SQL installer in unattended mode with a shell command like: “start /wait setup.exe /qb /settings c:\template.ini” in which the configuration settings are passed in using the template.ini file or passing all the configuration parameters as command line arguments.
So I took out the code they present in the article, corrected a few minor problems and created a basic installation wrapper that offer the option to select if install the SQL Engine (along with the database files or with a series of scripts to create the databases...this implementation is left to you in this sample project), one or more MSI packages that install the real application software or both.
The wizard is graphically ugly to see (some screens follows) and you need to customize it to fir your company installation templates styles; the code behind surely need some refactoring but it actually works.
To be used the Installation Bootstrap requires that the SQLEXPR.EXE and the application MSI files are placed in the same directory of the bootstrap itself.
Converting this project to be used with VS 2005/2008 and the new .NET Framework is really easy.
Sample project:
We had the requirement of allowing the deployment of the database engine along with the application (ClickOnce is not an option in VS.2003 :D), the Setup project that comes along with VS 2003 rely on merge modules to install external components, but unfortunately no merge module exists for SQL Express (they have been deprecated). So I started looking around for a solution and I came to this msdn article: Embedding SQL Server Express into Custom Applications.
Basically they suggest to write down a wrapper around the installation of the two components (SQL Express and the application) and launch the SQL installer in unattended mode with a shell command like: “start /wait setup.exe /qb /settings c:\template.ini” in which the configuration settings are passed in using the template.ini file or passing all the configuration parameters as command line arguments.
So I took out the code they present in the article, corrected a few minor problems and created a basic installation wrapper that offer the option to select if install the SQL Engine (along with the database files or with a series of scripts to create the databases...this implementation is left to you in this sample project), one or more MSI packages that install the real application software or both.
The wizard is graphically ugly to see (some screens follows) and you need to customize it to fir your company installation templates styles; the code behind surely need some refactoring but it actually works.
Converting this project to be used with VS 2005/2008 and the new .NET Framework is really easy.
Sample project:

#1 da DotNetShoutout - Saturday March 2010 alle 01:15
Install SQL Serer (Express) with your Application at Guardian’s Home... Thank you for submitting this cool story - Trackback from DotNetShoutout...
#2 da Jeff Klawiter - Saturday March 2010 alle 01:15
You can use ClickOnce or a standard setup project with .NET 1.1. Create your setup project in VS 2003, building it and then include it in a VS 2005/2008 setup project. To make a custom install just take the package located at (for 2005) C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\SqlExpress. Copy it and edit the xml file to pass custom parameters to set up sql express differently
#3 da micaleel - Saturday March 2010 alle 01:15
Cool, this is certainly a good read.
#4 da Saverio Tedeschi - Saturday March 2010 alle 01:15
Grazie, Alessandro.
#5 da Li Wei - Saturday March 2010 alle 01:15
Cool.Thanks.
#6 da Guardian - Saturday March 2010 alle 01:15
Yep it can be, but the purpose of that wizard I created was to simply build the command lines to pass to the actual SQL Express setup (which will run in silent mode), so you can skip all of that, pre-format your string and call the SQL Express installer directly, just showing a progress bar to the user.
#7 da mahnaz - Saturday March 2010 alle 01:15
Thanks,It's perfect.
#8 da Hanzie - Saturday March 2010 alle 01:15
Hello, thnx for this great code. One question: When i wan't to use it i create a setup and deployment project to install you're application. Then with that installed application the end-user again has to install end-application and sql-server. So the user gets 2 setup programs to install. Isn't that confusing for the end-user?! Thanks
#9 da Daniele - Tuesday May 2010 alle 11:09
very useful code! :)