![]() |
Platforms, Frameworks & Libraries »
.NET Framework »
General
Intermediate
License: The GNU General Public License (GPL)
Dot Net Installer that automatically install MSDEBy John Kenedy S.KomThis project enable developer to create a setup package that automatically install MSDE and attach database |
C#, Windows (WinXP, Vista), SQL Server (SQL 2000), ADO.NET, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Download Installation.zip - 967.13 KB
Often programmers want to build a single installer package that can install the application along with prerequisites and database. Fortunately for database, programmer can use MSDE which can be distributed along with your application, but MSDE lacks of user interface so to configure it often we need to use command line.
This is the scenario :
1. Programmer want a single package that automatically install .NET Framework and then install MSDE and use the database for the application that programmer write.
2. In this tutorial the installation will create a new database instance, with a name specified by programmer, and it can detect whether this instance is exist and as for remove, so for safety programmer just create a unique database instance name.
3. The library then automatically attach database to this newly installed database instance. First I have written two projects which is required to be included in your solution. First is JohnKenedy.DataAccess and second is JohnKenedy.DataAccessModule. Because the installation code is coming along with this library.
4. The goal of this project is, user got the installation files, double click the exe, and click 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 click 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 write, run and connecting to the database without user knowing how to configure them. What user need to know is only how to use the application that programmer writes.
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 it is going to be deployed. From this project add reference to library name JohnKenedy.DataAccess
3. Download MSDE by clicking Download MSDE. 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 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 exist), 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 following, 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 start in this example is Login.cs, in the constructor after InitialilzeComponent, add codes that looks 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
1. First is Food, which is the application name that shows in your installtion progress
2. Second is JOHN, which is your computer name, you can just simply use "(local)" to replace "JOHN" to say that the installation 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 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 you suit.
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 success, the value will be both 0 which is automatically set by the application and so the application will just start normally.
1. Create a new Setup and Deployment project, in this sample is already exist name SetupMakanan.
2. In the application folder create a new folder name MSDE2000, and inside this folder create three folder name Msi, MSM, and Setup. Then inside MSM folder create a folder name 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 :
4. Now right click SetupMakanan project and select properties, then click Prerequisites button
And then select the second radio button, Download prerequisites from the same location in my application. Click OK, and save
5. 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 is the dot 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 run your application, it checks the IsInstall and IsRestart parameter 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.
This library is not fully for Installation, instead the library has Data Access feature, which the article can be found at http://www.codeproject.com/kb/library/johnkenedy_library.aspx
Installation is one of the feature in the library I develop recently. I have tested the Setup package in a computer that never had .NET and database installed, and it did successfully installed .net and msde and run the application smoothly.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 26 Jul 2008 Editor: |
Copyright 2008 by John Kenedy S.Kom Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |