Go: WinForm Package auto-Install database

Source: Internet
Author: User
Tags logical operators

VS2005 package and automatically install SQL database.
To create a deployment project
1. On the File menu, point to Add Project, and then select New Project.
2. In the Add New Project dialog box, select Setup and Deployment projects in the Project Types pane, and then select Setup Project in the Templates pane. In the Name box, type Setup1.
3. Click OK to close the dialog box.
4. The project is added to Solution Explorer, and the File System Editor opens.
5. In the Properties window, select the ProductName property and type the information management system.

II). Add the output of the main program project to the deployment project
1. In the File System Editor, select Application Folder. On the Action menu, point to Add, and then select Project Output.
2. In the Add Project Output Group dialog box, select your program in the Project drop-down list.
3. Click OK to close the dialog box.
4. Select the primary output and content files groups from the list, and then click OK.

III). Creating the Installer Class
1. On the File menu, point to New, and then select Project.
2. In the New Project dialog box, select Visual Basic project in the Project Types pane, and then select Class Library in the Templates pane. In the Name box, type Installdb.
3. Click Open to close the dialog box.
4. From the Project menu, select Add New Item.
5. In the Add New Item dialog box, select Setup class. In the Name box, type Installdb.
6. Click OK to close the dialog box.
7. The detailed code is attached.

IV). Create a Custom Installation dialog box
1. Select the "Setup1" project in Solution Explorer. On the View menu, point to Editor, and then select User interface.
2. In the User Interface Editor, select the startup node under install. On the Action menu, choose Add Dialog box.
3. In the Add Dialog dialog box, select the License Agreement dialog box, and then click OK to close the dialog box.
4. In the Add Dialog dialog box, select the text Box (A) dialog box, and then click OK to close the dialog box.
5. On the Action menu, select Move Up. Repeat this step until the text box (A) dialog box is on top of the installation folder node.
6. In the Properties window, select the BannerText property and type: Install the database.
7. Select the BodyText property and type: Setup will install the database on the target machine
8. Select the Edit1Label property and type: Database name:
9. Select the Edit1Property property and type CUSTOMTEXTA1
10. Select the Edit1Value property and type: Dbservers
11. Select the Edit2label property and type: Server name:
12. Select the Edit2property property and type CUSTOMTEXTA2
13. Select the Edit2value property and type: (local)
14. Select the Edit3label attribute and type: User name:
15. Select the Edit3value property and type: SA
16. Select the Edit3property property and type CUSTOMTEXTA3
17. Select the Edit4label property and type: password:
18. Select the Edit4property property and type CUSTOMTEXTA4
19. Select the Edit2Visible, Edit3Visible, and Edit4Visible properties and set them to True

Five). Create a custom action
1. Select the "Setup1" project in Solution Explorer. On the View menu, point to Editor, and then select Custom Action.
2. In the Custom Action Editor, select the installation node. On the Action menu, choose Add Custom Action.
3. In the Select Items in Project dialog box, double-click Application Folders.
4. Select the primary output from INSTALLDB (active) Item, and then click OK to close the dialog box.
5. In the Properties window, select the CustomActionData property and type "/dbname=[customtexta1"/server=[customtexta2]/user=[customtexta3]/pw D=[CUSTOMTEXTA4]/targetdir= "[targetdir]\" ".

Attached:/targetdir= "[targetdir]\" is the target path after installation, in order to obtain the installed path in the Installdb class, we set this parameter.

VI). Add Files
1. Add the SQL Server backup file DB.dat to the "Setup1" project (in Enterprise Manager, right-click Database--All work---backup database, back up as a file, named DB.dat)
2. Add the installation file Lisencefile.rtf to the "Setup1" project
3. In the User Interface Editor, select the license agreement, set the Lisencefile property to Lisencefile.rtf file
4. Typically, dependencies are automatically added to "Detected dependencies", and if not, we will manually add them to step 5)
CRYSTAL_MANAGED2003.MSM (if there is a crystal report)
DOTNETFXREDIST_X86.MSM (. NET must be required)
... (If you have references to other DLLs)
5. If you are using a crystal report, manually add the files you want to include: item-to-Add (add your program files) (including dotNetFramework and MDAC27), located at: C:\Program Files\Common Files \merge modules\, * for the necessary
The specific functions are as follows:
(Managed component MSM handles distribution of all managed components, including Windows Forms Viewer, Web Forms Viewer, and all Crystal decisions namespaces)
* CRYSTAL_MANAGED2003.MSM
Crystal_managed2003_chs.msm
(For all other files required to make the report run, the database access MSM handles its distribution.) These include database, export, and chart drivers. )
* CRYSTAL_DATABASE_ACCESS2003.MSM
Crystal_database_access2003_chs.msm
(KeyCode MSM handles the installation of Crystal decisions key numbers, note that the merge module is added, otherwise there is no "mergemouduleproperties" attribute)
* CRYSTAL_REGWIZ2003.MSM
(If the report file uses the ADO DataSet DataSet object, then the vc_user_crt71_rtl_x86_---. MSM and vc_user_stl71_rtl_x86_---. MSM modules must also package Included in the installation project. And the "module Retargetable Folder" entry for the file installation properties of these two modules must be modified to be a system directory)
Vc_user_crt71_rtl_x86_---. MSM
Vc_user_stl71_rtl_x86_---. MSM
(Many people often have query errors, you may add this)
5. Open the solution-right click on the properties of CRYSTAL_REGWIZ2003.MSM, "License key" in "Mergemouduleproperties" Fill in: Aap5gks0000gde100ds (this is the password for the registration number you used to generate the Crystal Report!) )


VII). Add Uninstall function when packing:
Method One:
1. Add file msiexec.exe to package items (usually found under c:\windows\system32\)
2. In the file system, select the application file folder, right-click on Msiexec.exe, select Create Shortcut, rename shortcut to "Uninstall".
3. Change the arguments of this shortcut to "/x {Product ID}", the value of the product ID is the ProductCode value of the package purpose.
Method Two: (recommended)
1. To install the package, make a note of ProductCode (choose Solution Explorer root directory such as Setup1, then view the property label, not the right-click property), use the following
2. Create a new console program with vs.net uninst.exe 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}") ' Changed to own ProductCode
End If
Myprocess.close ()
End Sub
End Module
3. Add the exe file of the console program Bin directory to the wrapper file

Method Two:

C # 's WinForm, the database is SQL2K,
The application includes the following files:
1.exe,1.dll,1.jpg,1.xml,donetsetup.exe and Database file 1.mdf,1.ldf (or database installation file 1.sql).
Packaging Requirements:
(1) Automatically detect whether the installation of Donet environment, if not installed, prompts for automatic installation.
(2) Install the database automatically (additional MDF or run 1.sql).
(3) You can customize some installation images or prompts on the installation screen.

Installation project:
Six subkeys: File system, registry, file type, user interface, custom action, launch condition.
The file system, registry, user interface, and custom actions are often used in the packaging process.
File system: Output project Files (four types: folder, project output, files, and assemblies) to the application folder, user's program menu, user Desktop, or create a shortcut (typically placed on the desktop or Program menu) file System Editor that represents the file system on the target computer, Use this tool to specify the location of the application file installation. In most cases, you want to place the application file in application folder or in a subfolder created under Application folder. After installation on the target computer, files from the application folder will be located in the Program Files/manufacturer/productname folder, where manufacturer is the installation of Visual Studio While ProductName is the name used for the deployment project. You can override both settings in the Properties window of the Setup project.
Registry: You can insert a key into the registry to create a registry key while the application is installed.
User interface: The system automatically provides a set of default dialog boxes that are displayed during installation. Depending on the type of project you are building, the set of dialog boxes provided is different. Using the user Interface Editor, you can reorder or delete dialog boxes. The dialog tree that is displayed in the editor contains two parts: Installation and administrator installation. The installation section includes the dialog box that is displayed when the end user runs Setup, and the Administrator installation section contains the dialog boxes that are displayed when the system administrator uploads the installer to a network location. If you want to build an installation that does not have a user interface, simply delete all the dialog boxes in the Installation section on the dialog tree. Alternatively, you can add a dialog box to the Setup project from a set of available templates.
Launch condition: Use the Launch Condition editor to define the conditions that must be met to successfully run the installation. For example, you can check for a specific version of the operating system. If the user tries to install on a system that does not meet the criteria, the installation is aborted. You can also configure launch conditions to search for a specific file, registry key, or component on the target computer. When you start the installation, Windows Installer performs search and condition evaluations and executes in the order shown in the Launch Conditions Editor.
Custom actions: Custom actions provide a mechanism for performing tasks at the end of an installation. For example, you might want to configure the database before you install the application, and you can use a custom action to complete the creation of the database. Custom actions are built as separate. dll or. exe files and then added to the project using the Custom Action Editor, which is related to the different installation phases. The Custom Action Editor includes several separate folders for placing binaries that perform Install, Commit, Rollback, or Uninstall tasks.
InstallerClass Property: If you add a custom action that inherits from the installer class (note which folder you want to overload and which corresponding method is to be overloaded), the property is set to true, otherwise the property is set to False (note: the entry for the. dll file to be specified when false) --entrypoint property).
Uninstall: You can provide an uninstall shortcut in the installation application, with the help of the system-provided uninstaller Msiexec.exe (in the C:/windows/system32 directory), and assigns the ProductCode property value of the installer project to the Arguments property of the shortcut (note: Add/x before the property value)
Installer class: Under the System.Configuration.Install namespace
The installer class has four methods that can be overloaded, namely Install,commit,rollback,uninstall.
Corresponds to four folders in a custom action: Install, submit, rollback, uninstall.
Database installation:
1. Additional Database
2. Execute the SQL statement that created the database
3. database file restore for full backup
You can deploy the files that can generate the database (detached database files, SQL script files, or full backup files) to the application folder, and then add the generated database code in the overloaded Install method (note: The code that generates the database should be called after the base class's Install method).
Unload the database: first delete the database, then call the base class's Uninstall method to delete the files in the application folder (the order can not be messy).
Several special points:
1. alawayscreate attribute in File system: This property can be specified as false, Then the condition property is empty when the Alawayscreate property is true (the Transitive property must be true to calculate the value of the Condition property). The Condition property can be used to add conditional logic to the Setup program, for example, to install a file only for a specific operating system version. It can also be used with file search, registry search, or component search to terminate the installation process when the specified item is not found. It can be a Windows Installer condition or property that contains a value, a Name property in a file, a registry, or a component search, or a combination of the preceding statements using logical operators.
2, create shortcuts (created in the program, can have as additional tasks, according to the user's choice, there is a choice to create):
Add Reference: COM tab and select Windows Script Host Object Model
Create object: Create an instance object of WshShell, and then use the object's CreateShortcut method to create an instance object of the Iwshshortcut interface, passed to CreateShortcut The parameter of the method is the full path to the shortcut that will be created, including the name of the shortcut.
Set properties: TargetPath, WorkingDirectory, WindowStyle, Description, iconlocation
Generate shortcut: Call the Iwshshortcut.save method to generate the shortcut file.
Url:http://greatverve.cnblogs.com/archive/2011/12/16/winform-install-data.html

Go: WinForm Package auto-Install database

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.