C # package the project and automatically install the SQL database

Source: Internet
Author: User
C # package the project and automatically install the SQL database

According to the needs of a netizen, the MVP Li honggen ". NET platform Web application was corrected. Program Osql usage error in "deployment (installation of database and automatic configuration)", passed the test.

1 ). Create a deployment project 1. Point to "add project" on the "file" menu, and select "new project ".

2. 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. 3. Click "OK" to close the dialog box.

4. The project is added to Solution Explorer and opened in the file system editor.

5. In the "properties" window, select productname properties and type information management system. 2 ). Add the output of the main program project to the deployment project. 1. In the file system Editor, select "application folder ". On the "operations" menu, point to "add" and select "project output ".

2. In the "add project output group" dialog box, select "your program" from the "project" drop-down list ".

3. Click OK to close the dialog box.

4. Select the "main output" and "Content File" groups from the list, and click "OK ".

3 ). Create installer Class 1. Point to "new" on the "file" menu, and then select "project ".

2. In the "new project" dialog box, select "Visual Basic Project" in the "project type" pane and select "class library" in the "template" pane ". In the "name" box, type installdb. 3. Click "open" to close the dialog box.

4. Select "Add new project" from the "project" menu ".

5. In the "Add new project" dialog box, select "Installer class ". In the "name" box, type installdb. 6. Click "OK" to close the dialog box.

7. Details Code Attached.

4 ). Create custom installation Dialog Box 1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "User Interface ".

2. In the User Interface Editor, select the "Start" node under "installation. On the "operations" menu, select "add dialog box ".

3. In the "add dialog box", select the "License Agreement" dialog box and click "OK" to close the dialog box.

4. In the Add dialog box, select the text box (A) and click OK to close the dialog box.

5. On the "operations" menu, select "Move Up ". Repeat this step until the "text box (a)" dialog box is located on the "Install Folder" node.

6. In the "properties" window, select the bannertext attribute and type: Install the database.

7. select the bodytext attribute and type: the installer will install the database on the target machine 8. select the edit1label attribute and type: Database Name: 9. select the edit1property property and type customtexta1 10. select the edit1value attribute and type dbservers 11. select the edit2label attribute and type: Server Name: 12. select the edit2property property and type customtexta2 13. select the edit2value attribute and type: (local)

14. select the edit3label attribute and type: Username: 15. select the edit3value attribute and type: SA 16. select the edit3property property and type customtexta3 17. select the edit4label attribute and type: Password: 18. select the edit4property property and type customtexta4 19. select the edit2visible, edit3visible, and edit4visible attributes, and set them to true ). Create a custom operation 1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "Custom operations ".

2. Select the "Install" node in the Custom operation editor. On the "operations" menu,

Select "add custom operation ".

3. In the "select project items" dialog box, double-click "application folder ".

4. Select "primary output from installdb (activity)" and click "OK" to close the dialog box.

5. in the "properties" window, select the customactiondata attribute and type "/dbname = [customtexta1]/Server = [customtexta2]/user = [customtexta3]/Pwd = [customtexta4]/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.

6 ). Add file 1. back up SQL server to a file dB. add dat to the "setup1" project (right-click the database in the Enterprise Manager> all jobs> back up the database and back up it into a file named dB. dat)

2. set the Installation File lisencefile. add RTF to "setup1" Project 3. in the User Interface Editor, select the license agreement and set the lisencefile attribute to lisencefile. RTF file 4. generally, dependencies are automatically added to "detected dependencies". If not, manually add them to Step 5)

Crystal_managed2003.msm (if there is a crystal Report)

Dotnetfxredist_x86.msm (. NET must be required)

...... (If any other DLL is referenced)

5. if a crystal report is used, manually add the file to be included: Project --> Add --> Merge Module (add your program file) (including dotnetframework and mdac27) at: C: * under \ Program Files \ common files \ merge modules \, the required functions are as follows: (the managed component MSM processes the distribution of all managed components, including windows form viewer, web form viewer, and all crystal decisions namespaces)

* Crystal_managed2003.msm crystal_managed2003_chs.msm. These include database, export, and chart drivers .)

* Crystal_database_access2003.msm crystal_database_access2003_chs.msm (keycode MSM processes crystal decisions key number installation. Note that the merging module is added; otherwise, the "mergemouduleproperties" attribute is not available)

* Crystal_regwiz2003.msm (if the report file uses the dataset DataSet object of ADO. net, vc_user_crt71_rtl_x86 _--. MSM and vc_user_stl71_rtl_x86 _--. The MSM module must also be included in the installation project. In addition, the "module retargetable folder" item of the File Installation attribute of the two modules must be changed to the system directory)

Vc_user_crt71_rtl_x86 _--. MSM vc_user_stl71_rtl_x86 _--. MSM (many people often encounter query errors. Please add this)

5. open solution --> right-click the attribute of crystal_regwiz2003.msm, and fill in the "license key" in "mergemouduleproperties": aap5gks1_gde100ds (this is the registration code used to generate the crystal report !)

7 ). Added the uninstall function during packaging: Method 1: 1.added the msiexec.exe file to the package overview page (generally found under c: \ windows \ system32)

2. Upload the program file in the file system, press "right" on "msiexec.exe", select "Uninstall" to create a shortcut, and rename the shortcut to "Uninstall ". 3. change arguments of this shortcut to "/X {product ID}", and the value of product ID is the productcode encoding value of the packaging destination.

Method 2: (recommended)

Hosts file 'power by: landlordh 'for 2000, XP, 2003 module uninstall sub main ()

Dim myprocess as process = new process if system. environment. osversion. tostring. indexof ("nt 5") Then myprocess. start ("msiexec", "/X {2b65d4a9-c146-4808-ab4b-321fb0779559}") 'change to your own productcode end if myprocess. close ()

End sub end module 3.add the exefiles in the binlog of the console program to the package program file. The shortcut for creating uninst.exe in the program group is attached: installdb. VB class, to add reference system. configuration. install. DLL: Imports system. componentmodel imports system. configuration. install public class installer1 inherits system. configuration. install. installer # region "code generated by the component designer" Public sub new ()

Mybase. New ()

'The call is required by the component designer.

Initializecomponent ()

'Add any initialization end sub after initializecomponent () 'installer overwrites dispose to clear the component list.

Protected overloads overrides sub dispose (byval disposing as Boolean)

If disposing then if not (components is nothing) Then components. Dispose ()

End if mybase. Dispose (disposing)

End sub 'private components as system. componentmodel. icontainer 'required by the component designer. Note: The following procedure is required by the component designer.' You can use the component designer to modify this procedure.

'Do not use the code editor to modify it.

Private sub initializecomponent ()

Components = new system. componentmodel. container end sub # End Region Public overrides sub install (byval statesaver as system. Collections. idictionary)

Mybase. Install (statesaver)

If not installdb () then' fails to install me. Uninstall (statesaver)

Exit sub end if deletefile (string. Format ("{0} dB. dat", me. Context. Parameters. Item ("targetdir ")))

End sub public overrides sub uninstall (byval statesaver as system. Collections. idictionary)

Related Article

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.