Introduction
It is common to distribute MSDE 2000 with your .NET application. There are different ways of doing this like, using merge modules or writing one more .NET application to particularly install MSDE 2000. We will be seeing the latter approach here. In my previous articles, I have used custom actions for such installations but here we cannot use custom actions because the .NET setup application does not allow another setup to run from within it. Therefore in such situations you need to create a .NET application which will first install your main .NET application and then MSDE 2000. Make sure the .NET Framework is installed on the target machine because your starting application is made using any one of the .NET languages. You can use AUTORUN file on your CD to install the .NET Framework and then you can run your application which will install both the main application and the MSDE 2000. Before starting the design of the application, many of us would like to know what MSDE is. So let’s start with the basics of MSDE.
Overview of MSDE
The Microsoft SQL Server 2000 Desktop Engine (MSDE 2000) is a data engine built and based on the core SQL Server technology. With support for single and dual processor desktop computers, MSDE 2000 is a reliable storage engine and query processor for desktop extensions of enterprise applications. The common technology base shared between the SQL Server and MSDE 2000 enables developers to build applications that can scale seamlessly from the portable computers to multiprocessor clusters. Designed to run in the background, supporting transactional desktop applications, MSDE 2000 does not have its own user interface (UI) or tools. Users interact with MSDE 2000 through the application in which it is embedded. MSDE 2000 is packaged in a self-extracting archive for ease of distribution and embedding. In addition, MSDE 2000 can be built into applications and redistributed royalty-free with Microsoft development tools, such as Microsoft Visual Studio® .NET and Microsoft Office XP Developer Edition. This allows developers to build enterprise class reliability and advanced database features into their desktop applications. An attractive alternative to using the Microsoft JET database, MSDE 2000 is designed primarily to provide a low-cost option for developers who need a database server that can be easily distributed and installed with a value-added business solution. Because it is fully compatible with other editions of SQL Server, developers can easily target both SQL Server and MSDE 2000 with the same core code base. This provides a seamless upgrade path from MSDE 2000 to SQL Server if an application grows beyond the storage and scalability limits of MSDE 2000.
Download MSDE 2000
Downloadable file name: SQL2kdesksp3.exe SP3a. SP3a updates for MSDE includes updates and new installations for the database components of the instances of the SQL Server 2000 Desktop Engine, including: the Desktop data engine. Database client connectivity components include the OLE DB Provider for SQL Server, the SQL Server ODBC driver, and the client NET-Libraries. SQL2kdesksp3.exe includes all the files that are required to install a new instance of the Desktop engine (.msi files), to upgrade all the existing instances of the Desktop engine (.msp files), as well as to consume merge modules (.msm files) into applications.
MSDE 2000 setup parameters
Parameter | Description |
SAPWD="AStrongPassword" | Specifies a strong password to be assigned to the sa administrator login. |
INSTANCENAME="InstanceName" | Specifies the name of the instance. If INSTANCENAME is not specified, the setup installs a default instance. |
DISABLENETWORKPROTOCOLS=n | Specifies whether the instance will accept network connections from the applications running on other computers. By default, or if you specify DISABLENTWORKPROTOCOL=1 , the setup configures the instance to not accept network connections. Specify DISABLENETWORKPROTOCOLS=0 to enable network connections. |
SECURITYMODE=SQL | Specifies that the instance be installed in Mixed Mode, where the instance supports both Windows authentication and SQL authentication logins. |
DATADIR="data_folder_path" |
Specifies the folder where the setup installs the system databases, error logs, and installation scripts. The value specified for the data_folder_path must end with a backslash (\). For a default instance, the setup appends MSSQL\ to the value specified. For a named instance, the setup appends MSSQL$InstanceName\, where InstanceName is the value specified with the INSTANCENAME parameter. Setup builds three folders at the specified location: a Data folder, a Log folder, and a Script folder. |
TARGETDIR="executable_folder_path" |
Specifies the folder where the setup installs the MSDE 2000 executable files. The value specified for executable_folder_path must end with a backslash (\). For a default instance, the setup appends MSSQL\Binn to the value specified. For a named instance, the setup appends MSSQL$InstanceName\Binn, where InstanceName is the value specified with the INSTANCENAME parameter. |
You can install up to 16 copies, or instances, of MSDE 2000 and the SQL Server 2000 database engine on the same computer. One of the instances has no instance name, and is called the default instance. The other 15 instances must have unique instance names, and are called named instances. When installing a new instance of MSDE 2000 Release A, use the Desktop Engine Setup.exe INSTANCENAME
parameter to specify the name of a named instance. If you do not specify an instance name, the setup will attempt to install a default instance.
Overview of the installer application
The logic used is very simple. We are just creating a setup.ini file by passing the setup parameters collected through form and by using this setup.ini to run setup.exe.
Using the demo application
For running the demo application you need to have MSDE 2000. I am not providing it with my application because of the size restrictions (70 MB). Just download the MSDEInstaller application in one folder and place the MSDE 2000 folder in the same directory and start using the application. Sufficient tool tips are provided for your help.
Using the source code
Some important functions are discussed below:
To get the program files of the system
You can see that default path is set for the Target directory and the Data directory. This is possible by using Environment.GetFolderPath
:
txtTargetDir.Text=
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Trim()+
"\\MSDE2000\\Binn";
txtDataDir.Text=
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).Trim()+
"\\MSDE2000\\Data";
To create setup.ini
setup.ini file is necessary from the installation point of view. The MSDE 2000 setup takes all the information needed for installation from this file. We will be passing all the information collected from the form to this file. We will be using the IO operations to create this file:
if(rbLocal.Checked==true)
{
intInstallMode=1;
}
else
{
intInstallMode=0;
}
FileStream fsOutput =
new FileStream(Application.StartupPath.Trim()+"\\MSDE2000\\setup.ini",
FileMode.Create, FileAccess.Write);
StreamWriter srOutput = new StreamWriter (fsOutput);
string s1,s2;
s2="\"";
s1="[Options] DISABLENETWORKPROTOCOLS="+intInstallMode+"
SECURITYMODE=SQL TARGETDIR="+s2+txtTargetDir.Text.Trim()+s2+"
DATADIR="+s2+txtDataDir.Text.Trim()+s2;
srOutput.WriteLine(s1.ToString());
srOutput.Close ();
fsOutput.Close ();
To start the installation process
After collecting the parameters from setup.ini we will start installing MSDE 2000 by running setup.exe using System.Process
:
ProcessStartInfo psi = new ProcessStartInfo();
string strInstanceName="", strStrongPass="";
strInstanceName=txtInstanceName.Text.Trim();
strStrongPass=txtSPWD.Text.Trim();
psi.FileName=Application.StartupPath.Trim()
+@"\MSDE2000\setup.exe";
psi.Arguments= "INSTANCENAME="+strInstanceName+"
SAPWD="+strStrongPass+" DISABLENETWORKPROTOCOLS="+intInstallMode+
" SECURITYMODE=SQL TARGETDIR="+
s2+txtTargetDir.Text.Trim()+s2+"
DATADIR="+s2+txtDataDir.Text.Trim()+s2 +"/qb";
p.StartInfo=psi;
p.Start();