. Net Package and install and uninstall MSDE

Source: Internet
Author: User

1. Create the "setup1" Installation Project
On the "file" menu, point to "add project" and select "new project ".
In the Add new project dialog box, select "Install and deploy Project" in the "project type" pane, and select "Install Project" in the "template" pane ". In the "name" box, type "setup1 ".
Click OK to close the dialog box.
The project is added to Solution Explorer and opened in the file system editor.
In the Properties window, select the productname attribute and type "telemetry watermark data receiving software ".

Right-click setup1 and choose add project output to add your application.ProgramAnd corresponding class libraries and database files are added to the installer. open the file system interface, find the application folder, right-click your application, and create two shortcuts,
Right-click the attribute to specify the corresponding icon and drag it to the "program" menu and the user desktop. Complete the preliminary installation.

2. Add the uninstall program
In the packaging project, locate the "msiexec.exe" file (generally found in c: \ windows \ system32 (in the system directory ).

In the file system view, select the application file, right-click msiexec.exe and choose "create shortcut", and rename the shortcut to "uninst ".

Change the shortcut argmuments to "/X {product ID}", and the value of the product ID is the productcode attribute value of the package project.

3. Package MSDE SP3

Select "File System Editor", point to "add" on the "View" menu, and select "merge module ..." (Merge Moudle). In the Add module, locate the directory where the MSDE SP3 Installation File is located, and add all the files under MSM, MSM \ 1033, and MSM \ 2052.

In the "Search Path" in the properties of the setup1 installation project, add the following directories: MSM, MSM \ 1033, and MSM \ 2052.

Click "generate solution" under the "generate" menu to compile setup1 to install the project.

4. Automatically attach a database
Add a project in the solution. The project type is Windows class library. Then add the new project-> installer class. Open installer1.cs and switchCodeEdit the view and add the following code:

 

Code
1 Private   Void Createdatabase ()
2 {
3 // Start the SQL service to prevent the service from being started after installation.
4 PROCESS p =   New Process ();
5 P. startinfo. filename =   " Cmd.exe " ;
6
7 P. startinfo. useshellexecute =   False ;
8 P. startinfo. redirectstandardinput =   True ;
9 P. startinfo. redirectstandardoutput =   True ;
10 P. startinfo. redirectstandarderror =   True ;
11 P. startinfo. createnowindow =   True ;
12
13 P. Start ();
14 P. standardinput. writeline ( " Net start MSSQL $ hw1000 " );
15 P. standardinput. writeline ( " Exit " );
16 P. standardoutput. readtoend ();
17
18 String Strsql =   String . Format ( " Server = {0}; user id = {1}; Password = {2}; database = Master " , " (Local) \ hw1000 " , " SA " , " SA " );
19 String Strmdf =   This . Context. Parameters [ " Targetdir " ] +   " Database \ shandongshuiqing. MDF " ;
20 String Strldf =   This . Context. Parameters [ " Targetdir " ] +   " Database \ shandongshuiqing_log.ldf " ;
21 // Logwriter. logevent ("MDF path:" + strmdf );
22 String STR;
23 Sqlconnection myconn =   New Sqlconnection (strsql );
24 Str =   " Exec sp_attach_db @ dbname = n' shandongshuiqing ', @ filename1 = N' "   + Strmdf +   " ', @ Filename2 = N' "   + Strldf +   " ' " ;
25 Sqlcommand mycommand =   New Sqlcommand (STR, myconn );
26 Myconn. open ();
27 Mycommand. executenonquery ();
28 Myconn. Close ();
29 }
30
31 Protected   Override   Void Onafterinstall (system. Collections. idictionary savedstate)
32 {
33 Base . Onafterinstall (savedstate );
34 Try
35 {
36Createdatabase ();
37}
38 Catch (Exception ex)
39 {
40Throw NewException (ex. tostring ());
41}
42 }

Compile the installdb project.

 

5. Create a custom operation
In Solution Explorer, select and install the project "setup1", point to "Editor" in the "View" menu, and select "Custom operations ".

Select the "Install" node in the "Custom operation Editor. Right-click "add custom operation", select "application folder" from the options of the project, and select "primary output from installdb (activity )".

In the Properties window, select the customactiondata attribute and type "/targetdir =" [targetdir] \ "".

Appendix:/targetdir = "[targetdir] \" is the target path after installation. To obtain the path after installation in the installdb class, we set this parameter.

Generate Installer

 

6. Modify the installer
Use the orca MSI Installation File modifier to open the generated installation package (setup1.msi) file, in the table column on the left

Select the "installexecutesequence" table and modify the following attribute values:

Change getsqlstates. xxxxxx 103 to 421

The value of removeexistingproducts is changed to 1800.

Change the installinitialize value to 1799.

In installuisequence

Select the "installuisequence" table and modify the following values:

Change getsqlstates. xxxxxx 103 to 421

Select the "property" table and add the following three attributes:

Sqlinstancename: msdedh instance service name

Sqlsecuritymode: SQL)

Sqlsapwd: SA Password


All of them have been completed. After the software is installed, the test passes and the uninstallation passes.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.