How to package and deploy and install Asp.net and sqlserver

Source: Internet
Author: User

1. Prepare necessary documents
1. the SQL script file generates tables and stored procedures required during installation;

After it is generated, name it dB. SQL (case sensitive)
2. lisencefile. rtf Installation File, because my system is personal and free, so there is no. This will also be used in the future.
2. Create a deployment project in your existing project:
1. Point to "add project" on the "file" menu and select "new project ". (Figure 1-2)
2. In the "Add new project" dialog box, select "Install and deploy Project" in the "project type" pane, and select "Web Installation Project" in the "template" pane ". In the Name box, type test installer. (Figure 1-3)
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 gcrm.

(1-2)

(Figure 1-3) for the functions of other projects, see webcast.
3. Add the output of the vbnettest project to the deployment project (assume that your virtual directory is sqlandaspnet)
1. In the file system Editor, select Web application folder ". On the "operations" menu, point to "add" and select "project output ". (Figure 1-4)
2. In the "add project output group" dialog box, select "sqlandaspnet" 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 ". (Figure 1-5)

(Figure 1-4)

(Figure 1-5) for other functions, see webcast. The source file is the file of all projects.
4.

Create custom installation dialog box
1. Select the "test installer" project in Solution Explorer. On the "View" menu, point to "Editor" and select "User Interface ". (Figure 1-6)
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. (Note: I didn't add it because I still don't need it for the time being. You need to add it)
4. In the Add dialog box, select the text box (A) and click OK to close the dialog box. (Figure 1-7)
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 database ..
7. Select the bodytext attribute and type: InstallProgramThe database will be installed 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: gscrm.
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: User name :.
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 edit2visible and edit3visible, and set them to false. (Figure 1-8)


(Figure 1-7)


(Figure 1-8)

(5). Create a custom operation
1. Select the "test installer" project in Solution Explorer. On the "View" menu, point to "Editor" and select "Custom operations ". (Figure 1-9)
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 "main output from dbcustomaction (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] \". (Figure 1-10)

Attachment/targetdir = "[targetdir] \" is the target path after installation. To obtain the path after installation in the dbcustomaction class, we set this parameter.
In addition, the installation path can also be obtained through reflection:
Dim ASM as system. reflection. Assembly = _
System. reflection. Assembly. getexecutingassembly
Msgbox ("ASM. Location ")

(Figure 1-9)

(Figure 1-10)
Haha, it is much better. The key step is the rest. I spent a lot of time researching it.
(6) Create an installer class
1. Point to "new" on the "file" menu and 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 dbcustomaction.
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 dbcustomaction.
6. Click OK to close the dialog box. (Figure 1-11, 1-12)
Note: You can create a simple installation file on the original project.

(Figure 1-11)
Added:

(Figure 1-12) the SQL file must be added.
(7)
Add File
1. Add the script file dB. SQL generated by SQL Server to the "test installer" project (Figure 1-12)
2. Add the Installation File lisencefile. rtf to the "test installer" project.
3. In the User Interface Editor, select the license agreement and set the lisencefile attribute to the lisencefile. rtf file.
(8)
The code below is the most important part of the entire deployment.

SetCodeAdd to the installer class, dbcustomaction. VB class

Copy code The Code is as follows: Imports system. componentmodel
Imports system. configuration. Install
Imports system. Io
Imports system. Reflection
<Runinstaller (true)> public class dbcustomactionclass dbcustomaction
Inherits system. configuration. Install. Installer
Code generated by the component designer # region "code generated by the component designer"
Public sub new ()
Mybase. New ()
'The call is required by the component designer
Initializecomponent ()
'Add any initialization after initializecomponent () is called.
End sub
'Installer override dispose to clear the component list.
Protected overloads overrides sub dispose () sub dispose (byval disposing as Boolean)
If disposing then
If not (components is nothing) then
Components. Dispose ()
End if
End if
Mybase. Dispose (disposing)
End sub
Private components as system. componentmodel. icontainer
<System. Diagnostics. debuggerstepthrough ()> private sub initializecomponent ()
End sub
# End Region
'Execute SQL statements
Private sub executesql () sub executesql (byval conn as string, byval databasename as string, byval SQL as string)
Dim mysqlconnection as new sqlclient. sqlconnection (conn)
Dim command as new sqlclient. sqlcommand (SQL, mysqlconnection)
Command. Connection. open ()
Command. Connection. changedatabase (databasename)
Try
Command.exe cutenonquery ()
Finally
'Close connection
Command. Connection. Close ()
End try
End sub
Public overrides sub install () sub install (byval statesaver as system. Collections. idictionary)
Mybase. Install (statesaver)
'------------------------ Create a database -------------------------------------------------
Try
Dim connstr as string = string. format ("Data Source = {0}; user id = {1}; Password = {2}; persist Security info = false; packet size = 4096", me. context. parameters. item ("server"), me. context. parameters. item ("user"), me. context. parameters. item ("PWD "))
'Create a database based on the input database name
Executesql (connstr, "Master", "create database" + me. Context. Parameters. Item ("dbname "))
'Call osql to execute the script
Dim sqlprocess as new system. Diagnostics. Process
Sqlprocess. startinfo. filename = "osql.exe"
Sqlprocess. startinfo. arguments = string. format ("-U {0}-P {1}-d {2}-I {3} dB. SQL ", me. context. parameters. item ("user"), me. context. parameters. item ("PWD"), me. context. parameters. item ("dbname"), me. context. parameters. item ("targetdir "))
Sqlprocess. startinfo. windowstyle = processwindowstyle. Hidden
Sqlprocess. Start ()
Sqlprocess. waitforexit () 'waiting for execution
Sqlprocess. Close ()
'Delete the script file
Dim sqlfileinfo as new system. Io. fileinfo (string. Format ("{0} dB. SQL", me. Context. Parameters. Item ("targetdir ")))
If sqlfileinfo. exists then
Sqlfileinfo. Delete ()
End if
Catch ex as exception
Throw ex
End try
'--------------------- Write the connection string to Web. config -----------------------------------
Try
Dim fileinfo as system. Io. fileinfo = new system. Io. fileinfo (Me. Context. Parameters. Item ("targetdir") & "\ WEB. config ")
If not fileinfo. exists then
Throw new installexception ("No configuration file found ")
End if
'Instantiate XML document
Dim xmldocument as new system. xml. xmldocument
Xmldocument. Load (fileinfo. fullname)
'Find the node in the deleetask'
Dim node as system. xml. xmlnode
Dim foundit as Boolean = false
For each node in xmldocument. Item ("configuration"). Item ("etettings ")
If node. Name = "add" then
If node. Attributes. getnameditem ("key"). value = "connstring" then
'Write the connection string
Node. attributes. getnameditem ("value "). value = string. format ("Persist Security info = false; Data Source = {0}; initial catalog = {1}; user id = {2}; Password = {3 }; packet size = 4096; pooling = true; Max pool size = 100; min pool size = 1 ",_
Me. context. parameters. item ("server"), me. context. parameters. item ("dbname"), me. context. parameters. item ("user"), me. context. parameters. item ("PWD "))
Foundit = true
End if
End if
Next Node
If not foundit then
Throw new installexception ("the Web. config file does not contain connstring connection string Settings ")
End if
Xmldocument. Save (fileinfo. fullname)
Catch ex as exception
Throw ex
End try
End sub
End Class

The processclass, which is somewhat difficult, calls the osql.exe program to execute the SQL statements osql-u,-P,-D,-I.
The modification code of Web. config is implemented using XML syntax. Not difficult to understand.
Finally compiled and generated!

Installation interface:

Haha, I finally finished writing, and I don't know if I have written it.
Finally, I would like to thank Mr. Li honggen and Microsoft's lecturers. Combined with their common experience, the deployment is really simple.

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.