Pack, and automatically install SQL database

xiaoxiao2021-03-06  18

A) Create a deployment project

1. Point "Add Project" on the File menu and select New Project.

2. In the Add New Project dialog box, select Install and Deploy Projects in the Project Type pane, then select "Install Project" in the Template pane. Type setup1 in the Name box.

3. Click "OK" to close the dialog.

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

5. In the Properties window, select the ProductName property and type the 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 "Operation" menu, point to Add, 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.

4. Select the "Main Output" and "Content File" group from the list, and then click OK.

3) Create an installer class

1. Point "New" on the File menu and select "Project".

2. In the New Project dialog box, select "Visual Basic Project" in the Project Type pane, then select "Class Library" in the Template pane. Type InstallDB in the Name box.

3. Click "Open" to close the dialog.

4. Select "Add New Item" from the Project menu.

5. Select "Install Program Class" in the Add New Item dialog. Type InstallDB in the Name box.

6. Click OK to close the dialog.

7. After detailed code.

Four) Create a custom installation dialog

1. Select the "Setup1" item in the Solution Explorer. Point "Editor" on the View menu and select User Interface.

2. In the User Interface Editor, select the "Start" node under "Install". On the Actions menu, select Add Dialog.

3. In the Add Dialog dialog box, select the Law Protocol dialog box, and then click Close the dialog box.

4. In the Add Dialog Box dialog box, select the Text Box (a) dialog box and click "OK" to close the dialog.

5. On the "Operation" menu, select "Top". Repeat this step until the text box (a) dialog is on the "Install Folder" node.

6. In the Properties window, select the bannerText property and type: Install the database.

7. Select the BodyText property and type: The installer will install the database on the target machine.

8. Select Edit1Label properties and type: Database Name:

9. Select the Edit1Property property and type CustomTexta1

10. Select Edit1Value properties and type: dbservers

11. Select Edit2Label attribute and type: Server Name:

12. Select the Edit2Property property and type CustomTexta2

13. Select Edit2Value properties and type: (local)

14. Select Edit3Label attribute and type: Username:

15. Select the Edit3Value property and type: SA

16. Select the Edit3Property property and type CustomTexta3

17. Select Edit4Label attribute and type: Password:

18. Select the Edit4Property property and type CustomTexta4

19. Select Edit2Visible, Edit3Visible, and Edit4Visible properties and set them to TRUE

5). Create a custom operation

1. Select the "Setup1" item in the Solution Explorer. Point "Editor" on the View menu and select Customize.

2. Select the "Install" node in the Custom Operation Editor. On the Actions menu, select Add Custom Action. 3. In the "Select Item" dialog box, double-click Application Folder.

4. Select "The main output from the InstallDB" item, and then click "OK" to close the dialog.

5. In the Properties window, select CustomActionData attribute and type "/ DBNAME = [CustomTexta1] / Server = [CustomTexta2] / user = [CustomTextA3] / PWD = [CustomTextA4] / Targetdir =" [Targetdir] / "".

Attachment: / targetdir = "[TargetDir] /" is the installed target path, in order to get the installed path in the installDB class, we set this parameter.

6). Add a file

1. Add SQL Server back up to file db.dat Add to "Setup1" project (right-click Database in Enterprise Manager -> All Work -> Backup Database, back up into a file, name DB.DAT)

2. Add the installation file LisnceFile.rtf to "Setup1" project

3. In the User Interface Editor, select the license agreement, set the LisenseFile property to the Lisncefile.rtf file.

4. Generally, it will automatically add dependencies to "detected dependencies". If not, then we must add it to step 5)

Crystal_managed2003.msm (if there is a crystal report)

DOTNETFXREDIST_X86.MSM (.NET must be required)

... (if there is a reference to other DLLs)

5. If you use a crystal report, manually add the file you want to include: Project -> Add-> Merge Module (Add your program file) (including DotNetFramework and MDAC27), located in: C: / Program Files / Common Files / Merge Modules / under, * is necessary

The specific functions are as follows:

(Managed Components MSM processes the distribution of all managed components, including Windows Forms Viewer, Web Form Viewer, and All Crystal Decisions Namespaces)

* Crystal_managed2003.msm

Crystal_managed2003_chs.msm

(For all other files you need to run the report, you access the MSM by the database to distribute it. These include databases, export, and chart drivers.)

* Crystal_Database_access2003.msm

Crystal_Database_access2003_chs.msm

(Keycode MSM handles the installation of the Crystal Decisions key number, note that the merge module is added, otherwise there is no "MergeMouduleProperties" attribute)

* Crystal_Regwiz2003.msm

(If the report file uses the ADO.NET Data Dataset object, then vc_user_crt71_rtl_x86 _---. Msm and vc_user_stl71_rtl_x86 _---. MSM module must also be included in the installation project. And the file installation properties of these two modules. "Module Retargetable Folder item must be modified to become a system directory)

VC_USER_CRT71_RTL_X86 _---. Msmvc_user_stl71_rtl_x86 _---. Msm

(Many people often have query errors, please add this)

5. Open Solution -> Right-click Crystal_Regwiz2003.msm's properties, "License Key" in "MergeMouduleProperties" Fill in: AAP5GKS0000GDE100DS (this is the password you generated by Crystal Report is the password of the registration number!)

7). Add uninstall function when packaged:

method one:

1. Add files Msiexec.exe in the package item (usually found in C: / Windows / System32 /

2. Select the application folder in the file system view, press the right click on MSIExec.exe, select Create Shortcut, Renovate the shortcut to "Uninstall".

3. Change this shortcut the arguments for "/ x {product ID}", the value of the product ID is the ProductCode property value of the package item.

Method 2: (recommended)

1. Mr. into the installation package, write down ProductCode (select Solution Explorer root directory such as setup1, then view the attribute tag, not the properties in right click), here you want to use

2. Establish a new console file 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}") 'change to its own ProductCode

END IF

myprocess.close ()

End Sub

End module

3. Add the EXE file of the console program bin directory to the package file, create uninst.exe shortcuts in the program group

Attachment:

InstallDb.vb class, add reference system.configuration.install.dll:

Imports system.componentmodel

Imports system.configuration.install

Public Class Installer1 Inherits System.configuration.install.installer

#REGION "Component Designer Generated Code"

Public Sub new () mybase.new ()

'This call is necessary for the component designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Installer Overwrites Dispose to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

The PRIVATETETS AS System.componentModel.icontainer (the process) required: The following procedure is that the component designer must use the component designer to modify this process. 'Don't use the code editor to modify it. private subinitializecomponent () 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, uninstall 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) 'performing inverse mounting MyBase.Uninstall (stateSaver) DeleteFile (String.Format ( "{0} DB.dat", Me.Context.Parameters.Item ( "targetdir" ))) End Sub

Private sub deletefile 'Delete the specified file TRY DEM DELFILE AS New System.io.fileinfo (Paths) if Delfile.exists the Delfile.delete () end if catch exception end End Sub

Private Sub Createsql (Byval Paths As String) Dim file as system.io.streamwriter Dim DB as string = string.format ("{0}", me.context.parameters.Item ("dbname")) DIM path as string = String.Format ("{0}", me.context.parameters.Text.StringBuilder S.Text.StringBuilder S.Append ("Use master" & vbcrlf) S.Append ("" & VBCRLF) S.Append ("if not exists (select * from sysdatabases where name = '" & db ")" & vbcrlf) S.Append ("" "& VBCRLF) S.Append (" Create Database "& DB & VBCRLF) S.Append ("& VBCRLF) S.Append (" & VBCRLF) S.Append ("IF EXISTS (Select * from sysdevices where name = 'dbdisk')" & vbcrlf) S.Append "Begin" & vbrlf) S.Append ("ELSE" & VBCRLF) S.Append ("Else" & vbcrlf) S.Append ("Else" & Vbcrlf) S.Append ("begin" & vbcrlf) S.Append (" EXEC SP_ADDUMPDEVICE 'DISK', 'DBDISK', '"& PATH &" DB.DAT' "& VBCRLF) S.Append (" & VBCRLF) S.Append ("RESTORE DATABASE "& DB & VBCRLF) S.Append (" from disk = '"& path &" db.dat' "& vbcrlf) S.Append (" with replace ") File =

New system.io.streamwriter (path) file.write (s.toString) Catch exception finally file.close () END TRY End Subprivate Function InstallDb () AS Boolean 'Install the database, call the automatic batch. Try 'creates temporary scripts createSQL (String.Format ("{0} mydb2000tp.sql", me.context.parameters.item ("targetdir"))' calls OSQL Execute Scripts Dim SqlProcess As New System.Diagnostics.Process SqlProcess. STARTINFO.FILENAME = "osql.exe" sqlprocess.startinfo.arguments = string.format ("-u {0} -p {1} -s {2} -i {3} mydb2000tp.sql", me.context.Parameters .Item ("User"), Me.Context.Parameters.Item ("PWD"), Me.Context.Parameters.Item ("Server"), Me.Context.Parameters.Item ("Targetdir") SqlProcess.StartInfo .WindowStyle = ProcessWindowStyle.Hidden sqlProcess.Start () sqlProcess.WaitForExit () 'awaiting execution sqlProcess.Close ()' delete the script file DeleteFile (String.Format ( "{0} Mydb2000tp.sql", Me.Context.Parameters.Item ("Targetdir")) Return True Catch EX AS EXCEPTION RETURN FALSE END TRY END FUNCTION

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-41794.html

New Post(0)