Click here to Skip to main content
Click here to Skip to main content

.NET Installer that automatically installs MSDE

, 26 Jul 2008 GPL3
Rate this:
Please Sign up or sign in to vote.
This project enables developers to create a setup package that automatically installs MSDE and attaches database

Introduction

Often programmers want to build a single installer package that can install the application along with prerequisites and database. Fortunately for database, programmers can use MSDE which can be distributed along with your application, but MSDE lacks user interface so to configure it often we need to use command line.

Scenario

This is the scenario:

  1. A programmer wants a single package that automatically installs .NET Framework and then installs MSDE and uses the database for the application that a programmer writes.
  2. In this tutorial, the installation will create a new database instance, with a name specified by the programmer, and it can detect whether this instance exists and as for removal, so for safety programmer just create a unique database instance name.
  3. The library then automatically attaches the database to this newly installed database instance. First I have written two projects which are required to be included in your solution. First is JohnKenedy.DataAccess and second is JohnKenedy.DataAccessModule. This is because the installation code is coming along with this library.
  4. The goal of this project is, user gets the installation files, double clicks the EXE, and clicks next and next following the instruction without the need to understand how to connect database, the database name, username, password and so on, user just clicks next and next, the application will install the .NET prerequisites, the database, and attach the database that programmer has created all automatically, and the application that programmer writes, runs and connects to the database without user knowing how to configure them. What user needs to know is only how to use the application that the programmer writes.

Steps

  1. Download the sample code I attach and extract it to D:\Software Pekerjaan\Makanan (I use for this example.)
  2. Assume the MenuMakanan project is the Windows Application project that you are creating and which is going to be deployed. From this project, add reference to library named JohnKenedy.DataAccess.

  3. Download MSDE by clicking here. Double click the .exe and by default it will extract to your C:\sql2ksp3. Copy the extracted contents to MenuMakanan project bin\debug\MSDE2000 folder.
  4. Detach your application's database to become MDF file, and copy the MDF file only to MenuMakanan project bin\debug\MSDE2000 folder. For this example, it is Food_Data.MDF which is contained in the download for example.
  5. In your application (MenuMakanan), add an Application Configuration file or app.config (in this sample, it already exists), and create two new keys in AppSettings section, read App.Config in sample for more information. Remember to set IsInstall=0, and IsRestart=0 as follows, because this will tell your application to install before running, IsRestart will be 1 if it is finished installing and requires to restart your computer so that the newly installed MSDE service is running.
    <add key="IsInstall" value="1"/>
    <add key="IsRestart" value="0"/>    
  6. In your startup Form or form that is first run when application starts in this example is Login.cs, in the constructor after InitialilzeComponent, add codes that look like this:
    public Login()
    {
        InitializeComponent();
                
        Installation _ins = new Installation(
            "Food", "JOHN", "MenuMakanan", "Food", 
    	"JOHNKENEDYDAL", "FOOD_Data.MDF");
        if (_ins.IsDone == false) _ins.ShowDialog();
        if (_ins.IsRestart == true)
        {
            Application.Exit();
            this.Close();
            return;
        }
    }

Remember to add using JohnKenedy.DataAccess; so that Installation class can be found. This Installation class accepts 6 parameters, which I explain below:

  1. First is Food, which is the application name that shows in your installation progress.
  2. Second is JOHN, which is your computer name, you can just simply use "(local)" to replace "JOHN" to say that the installation is done to the computer running Setup.
  3. Third is MenuMakanan, which is the new database instance that will be installed, this is similar with (local)\SQLExpress database instance that Microsoft installed when we install VS 2005, though this one is MSDE one. This name must be unique, and this database instance will only contain one database name which will be defined in the fourth parameter, and be used by your application only.
  4. Fourth is Food, which is the database name that the application installs.
  5. Fifth is JOHNKENEDYDAL, which is the sa password for the newly installed MSDE, this password is required when you use Enterprise Manager (SQL 2000) to connect to the database instance.
  6. Food_Data.MDF is your MDF file name, that is stored in MenuMakanan project bin\debug\MSDE2000 folder. You can change this as it suits you.

As you notice, there will be code to check IsDone and IsRestart, left both of this checking as it is, since it is the condition that Installation class left for us to tell the main Startup Form what to do, whether to close the application or to show the form.

Now compile the application. Your compiled MenuMakanan.exe will automatically install your application because the configuration is IsInstall=1 and IsRestart=0, and if the installation succeeds, the value will be both 0 which is automatically set by the application and so the application will just start normally.

Create Setup and Deployment Package

  1. Create a new Setup and Deployment project, in this sample it already exists with name SetupMakanan.
  2. In the application folder, create a new folder name MSDE2000, and inside this folder create three folder names Msi, MSM, and Setup. Then inside MSM folder, create a folder names 1033. This structure is the same with the MSDE extracted folder earlier in Step 3, we then add files to these folders MSDE2000, Msi, MSM, 1033, and Setup folder according to the MSDE extracted folders.
  3. Add Food_Data.MDF to MSDE2000 folder, because the Installation class will look for the filename in this folder. After step two and three, it will look like:

    create_setup.JPG
    Click here for a bigger image

  4. Now right click SetupMakanan project and select properties, then click Prerequisites button:

    set_prerequisites.JPG

  5. And then select the second radio button. Download prerequisites from the same location in my application. Click OK, and save.

  6. Build your whole solution, and then build SetupMakanan project, and you will see in SetupMakanan project debug folder Setup.exe SetupMakanan.msi, and two new folders, one is Windows Installer 3_1 and another is DotNetFX35 which are the .NET prerequisites.

Now you can ship these files to a CD or zip it for distribution, the Setup application will install prerequisites and then your application to the folder. And when user runs your application, it checks the IsInstall and IsRestart parameters to determine whether database installation is needed, if yes, then it will install it for user and then ask for restart and after restarting it will check again whether to attach database or not, if yes then it will attach, and finally it will run your application.

History

This library is not fully for Installation, instead the library has Data Access feature, which article can be found here.

Installation is one of the features in the library I developed recently. I have tested the Setup package in a computer that never had .NET and database installed, and it did successfully install .NET and MSDE and run the application smoothly.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

John Kenedy S.Kom
Software Developer (Senior)
Singapore Singapore
I write code mostly in C#, VB.NET, PHP and Assembly.

Comments and Discussions

 
GeneralAbout Setup Pinmemberrentcoder20-Mar-09 1:48 
Generaltwo .mdf's Pinmembergrks22-Dec-08 2:49 
QuestionWhy MSDE? PinmemberPaul Conrad27-Jul-08 11:31 
AnswerRe: Why MSDE? PinmemberJohn Kenedy S.Kom27-Jul-08 20:42 
Is SQL Server 2005 Express free? Where can I download it? If possible I am going to create installer for it.
 
Thanks
GeneralRe: Why MSDE? PinmemberPaul Conrad27-Jul-08 20:47 
GeneralRe: Why MSDE? PinmemberJohn Kenedy S.Kom28-Jul-08 6:36 
GeneralRe: Why MSDE? PinmemberPaul Conrad28-Jul-08 6:42 
GeneralRe: Why MSDE? PinmemberJohn Kenedy S.Kom28-Jul-08 9:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 27 Jul 2008
Article Copyright 2008 by John Kenedy S.Kom
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid