Deployment of web applications under the NET platform (installation database and automatic configuration)
Li Honggen
Deploying a Web solution is more convenient under the .NET platform. We can use Visual Studio.net 2003 to add a web installation project, add the primary output and content files of the project in the deployed File System Editor, which is very simple to complete the production of the installer. However, the installer that is made is just the DLL file compiled by the web page and the ASP.NET program to the IIS directory of the target machine. For a general application, you can use the Access database, you can pack it into the installer together. If the database is SQL Server, you need to install the database when deploying, the installation program will be complex, and we need to customize the installer class. The SQL script is executed in the installer class and the connection string is written to Web.config. l Installing the Database Microsoft MSDN describes the establishment of a database when deploying an application. Such as: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxwlkwalkthroughusingcustomActiontOcreatedTabaseDuringInstallation.asp This method is to create a installer class, call in the installer class ADO.NET performs SQL statements (SQL statements in a text file) to create a database.
However, this approach has a problem. If you generate all the schedule, view, stored procedures with SQL Server2000, use ADO.NET to execute this script file, will have many "Go" statements in the script. An error occurred. Of course, we can replace "Go" into a newline, and use the ADO.NET article to execute the SQL statement. Obviously, such efficiency is relatively low.
The best way is to call OSQL execution scripts. (Or create a CMD file for a database project, and the CMD file is also called OSQL when the database is established.
First, we create a new ASP.NET web application, http: // localhost / vbnettest, and open the VBNetTest project
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 Item Type pane, then select "Web Installation item" in the Template pane. Type Test Installer 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 GCRM.
will
VBNettest
The output of the project is added to the deployment project
1. In the File System Editor, select the Web Application folder. On the "Operation" menu, point to Add, then select "Project Output".
2. In the Add Project Output Group dialog box, select "VBNetTest" 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.
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 dbcustomAct 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 dbcustomAct in the Name box.
6. Click OK to close the dialog.
Create a custom installation dialog
1. Select the Test Installer project 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 the Edit1Label property and type: Database Name:.
9. Select the Edit1Property property and type CustomTexta1.
10. Select the Edit1Value property and type: GSCRM.
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 the Edit3Label property and type: Username:.
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 Edit2Visible, Edit3Visible, and Edit4Visible properties and set them to false.
Create custom operations
1. Select the Test Installer project 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" item from the DBCustomAction, and then click "OK" to close the dialog.
5. In the Properties window, select the CustomActionData property and type / dbname = [CustomTexta1] / Server = [CustomTexta2] / user = [CustomTexta3] / PWD = [CustomTextA4] / Targetdir = "[targetdir] /". Attached / targetdir = "[targetdir] /" is the installed target path, in order to get the installed path in the DBCustomAction class, we set this parameter.
In addition, the path after the installation can also be obtained by reflection:
DIM ASM as system.reflection.assembly = _
System.Reflection.Assembly.GetexecutingAsembly
Msgbox ("asm.location")
add files
1. Add the script file DB.SQL generated by SQL Server to the Test Installer project
2. Add the installation file LisenseFile.rtf to the Test Installer project
3. In the User Interface Editor, select the license agreement, set the LisenseFile property to the Lisncefile.rtf file.
Document in the project
:
Add code to the installer class, dbcustomaction.vb class
Imports system.componentmodel
Imports system.configuration.install
Imports system.io
Imports system.reflection
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)
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
End Sub
#End region
'Execute SQL statement
Private 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.executenonQuery ()
Finally
'Close Connection
Command.connection.close ()
END TRY
End Sub
Public overrides sub install (byval statesaver as system.collections.idictionary)
Mybase.install (StateSaver)
' ------------------------build 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"))
'Set up the database based on the input database name
ExecuteSQL (Connstr, "Master", "Create Database" Me.Context.Parameters.Item ("DBNAME"))
'Call OSQL execution script
Dim SqlProcess As New System.diagnostics.Process
SqlProcess.StartInfo.FileName = "Osql.exe"
SqlProcess.startinfo.rguments = 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 script files
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 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 the
Throw new installexception ("No configuration file found")
END IF
'Instantiate XML documentation
Dim xmldocument as new system.xml.xmldocument
XmlDocument.Load (fileinfo.fullname)
'Find nodes in appsettings
Dim node as system.xml.xmlnode
Dim foundit as boolean = false
For Each Node in XmlDocument.Item ("configuration"). Item ("appsettings")
If node.name = "add" then
If node.attributes.getnamedItem ("key"). Value = "connString" then
'Write 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 notfactim
Throw new installexception ("Web.config file does not contain connString connection string settings"))
END IF
XMLDocument.save (fileinfo.fullname)
Catch exception
Throw EX
END TRY
End Sub
END CLASS
Finally compile generation!
Installation interface:
Disclaimer: The right to copyright and interpretation of this article belongs to Li Honggen, if you need to reprint, please keep your full content and this statement.
QQ: 21177563 MSN:
Lihonggen@hotmail.com
Column: http://www.9cbs.net/develop/author/netauthor/lihonggen0/0/
Author Blog:
http://blog.9cbs.net/lihonggen0/0/
related articles
SQL Server 2005 installation and interface screenshots, new features. Set the page-opening of the SQL Server stored procedure in VB6 and VB.NET, the page of the SQL Server sends a new way of sending an email. Outlook development technology under theNET platform
Comments on this article
9CBS netizen (2004-10-25) Will Yong C # change how to implement Dede111 (2004-10-18), the same installation - not reference the object to the object instance! Why? ? ? ?
9CBS netizen (2004-08-31) is also compiled, but the appearance of the installation - not reference the object to the object instance!
9CBS netizen (2004-08-31) found to find CustomActionData!
9CBS User (2004-08-31) In the Properties window, select the customActionData attribute and type / dbname = [CustomTexta1] / server = [CustomTexta2] / user = [CustomTexta3] / PWD = [CustomTextA4] / Targetdir = "[ Targetdir] / ". Didn't see CustomActionData? ? This property is. ///
OutofMemory and large memory use from Riskuo's Blog keyword. NET OutofMemory exception and large memory usage from last year Our server occasionally throw outofMemoryException, that is, there is not enough memory to continue executing an exception . This problem will still occur if the server memory is added to 4G. Software is a third-party simulator for UO. In fact, from the task manager, you can see that the software takes up about 1 g of memory, of course, because of the GC, there is about 600M in the actual software. To avoid more than 1G multi-memory occupation, and throw OutofMemory exception, setting the mandatory GC when the memory occupies a certain value, and a bit can lose a few hundred megabytes, but it is not completely solved. Recently, foreign forums posted relevant processing methods, and turned over, I hope to help friends who meet similar problems. For 2G memory servers, .NET can only use 1.2G memory. For a 4G memory server, .NET can use 2.4G memory. However, the system needs to be set as follows: 1, add / 3GB switches in the boot.ini file. [boot loader] Timeout = 30DEFAULT = MULTI (0) Disk (0) RDisk (0) Partition (2) / Winnt [Operating Systems] Multi (0) Disk (0) RDisk (0) Partition (2) / Winnt = " ???? "" / 3GB2, in the command line window, enter the directory, such as CD "C: / Program Files / Microsoft Visual Studio .NET 2003 / VC7 / BIN" 3, run the link command: link -edit -lageaddressaware server. EXE (Server.exe is your .NET program) 4, your server.exe can use 2.4G memory
//
.NET installer Deploy SQL Server Database Select from YOUNTHER BLOG Keyword Deployment Installation Directory L Summary L Summary L Summary L. SQL Server Database in the installer 1. Perform database script files by calling OSQL 2. Script files are loaded as resource files. 3. Creating a database L summary After summing a project, the installer is a necessary process. If you need to deploy a database, make the production of the installation are more troublesome. Use Visual Studio.NET to make very easy to make applications and databases required in the deployment program. This article describes how to make an installer using Visual Studio.net, and how to deploy a database in the installer. This article assumes that you are familiar with ADO.NET. 1. The general installer's production of Visual Studio.net provides a very powerful and very convenient installer production. The general installer can refer to the following steps: (1) Newly built a new installation item in Visual Studio.NET (for general Windows applications) or web installation items (for web-based applications), such as SETUPFACE. (2) On the SETUPFACE in the project inside the solution, click the following view: Figure 1 The item appearing in the view view in the installer is the item that needs to be involved in the production of the installer. a. The file system section provides how to pack the DLL, which need to be installed to the target, and the DLL needed to be installed to the installer, and also provides shortcuts and files on the desktop and program menus in the target machine. Clip, etc. b. The Registry section provides how to add related key values in the registry of the target. c. File Types provide a file type to create a file type with an application on the target, and can add relevant right-click menu features to registered file types. For example, register a .pdf file, use your own program to open. d. User interface provides interfaces during installation, or you can create functions such as readme files, registration code checks, etc. according to your needs. Some basic pictures have been provided when creating projects. e. Custom operation section mainly provides how to complete different work in different stages of installation. For example, create a database during the installation process, delete the database during the uninstall process. F. Starting Conditions section provides what conditions need to do before installing your application. Visual Studio.net provides a function of searching for start conditions on a user's computer. For example, a program is required to be installed, you can do it by searching the file system or search the registry. (3) Select the file system in the view, you will see the following screen: Figure 2 File System Interface If you need to complete a simple installer, select the file in the Add, select the application, Visual Studio.net The DLL you need to introduce the application (only for the application developed by Visual Studio.net, other programs are not tried), then create shortcuts in the user's "program" menu and user desktop, then Point shortcuts to choose to import applications imported in the application folder. (4) Finally, the project can be directly compiled and the installation procedure can be completed. If you need more control and modify the content during the installer, you can edit according to the different views mentioned in step (2). If you need to make a Web project installer, choose to create a web project when you create a project, and other parts are similar.
You can also directly refer to MSDN as follows: http: //msdn.microsoft.com/library/default.asp? URL = / library / en-us / vsintro7 / html / vxConatourofVisualstudio.asp 2. Deploying the SQL Server database in the installer Through the above introduction, the general application is very easy, basically, is the process of dragging your application into the installer. If your application runs requires support (such as SQL Server), the problem is more complicated. There are mainly aspects of the following aspects: (1) How to get the value of the installation screen, such as a username password entered. (2) How to design a program to interact with the database server, create a new database. How to get the value in the installer, please refer to the link below, here we don't do too much introduction.
We can complete the following code segments: process sqlprocess = new process (); sqlprocess.startinfo.FileName = "osql.exe"; sqlProcess.startinfo.arguments = string.format ("- u {0} -p {1 } -S {2} -i {3} ", this.uid, this.pwd, this.serverip, this.spath; // UID is the user name, the PWD is the password, Serverip is the IP of the target server, Spath is The path where the database script is sqlprocess.startinfo.windowstyle = processWindowStyle.hidden; sqlProcess.start (); sqlProcess.waitForexit (); // Waiting for SQLPRocess.close (); From above, this method must require the installer The client and the installed SQL Server can be used (OSQL is a program under the command line provided after SQL Server). In the actual test process, we found that if the user is selected to have a space for the installer , Such as; c: / program files / yourappliaction, installation failed. This is a relatively serious problem. 2.2 By loading the script file as a resource file to load from the previous discussion, we can see it, it is more troublesome when using the ADO.NET, you need a sentence to execute, if you use the script, there is a "Go" command in the script generated in the database. The problem will occur when executed in ADO.NET. Therefore, according to the analysis of the database installation script, we can use the following alternatives. During the installation of the database, there is no more than the following sections: (1) Creating a database (2) Creating a table (3) Creating a table (3) Creating a try or stored procedure and these three parts have the order, the order cannot be reversed, but each There is no order relationship during the process. During the test, we found that multiple tables or multiple stored procedures can be created in a statement. That is, we can perform the execution process in order to execute in the order. And we embed the database script as the resource file, as long as the execution is being executed, this will achieve the process of simplifying the creation of a command. Obtain a resource file code is as follows: (. "." Asm.GetManifestResourceStream (Asm.GetName () Name filename)) Assembly Asm = Assembly.GetExecutingAssembly ();; StreamReader str str = new StreamReader // filename you need to pick into the resource. As a resource file, simply import the file into your project, and change the generation operation to the embedded resource. Here we have a file stream of the file directly, so it can be read directly in the stream. We can complete the following: (1) Create a link to create a database. For example: Connectionstring = "Server = 127.0.0.1, uid = sa, pwd = pwd"; (2) Recreate a database link, the link Point to the created database. Connectionstring = "Server = 127.0.0.1, uid = sa, pwd = pwd, data = youdatabase"; (3) perform code for creating data tables and data stored procedures in new links. It should be noted that: Don't be named in your script, other commands can be executed directly.
The advantage of this method is that there is no SQL Server on the target machine that can be installed, and there is no problem with space in the file path. Of course, if your database is Oracle or DB2, you can also use a similar approach to implement. 2.3 Creating a database via sp_attach_db With the discussion above we have clear how to install the database. In the process of installing the database, in addition to creating a database through the database script, we can also attach the database through the system stored procedure sp_attach_db of SQL Server. Here we solve two questions: (1) Determine the location of the database file (.mdf and .ldf). (2) Execute the stored procedure. For problem 1 we can learn the first method of mounting data, that is, install. Mdf and .ldf on the target machine through the file system, then pass Assembly ASMBLY.GETEXECUTISSEMBLY (); string setuppath = asm.location; get file path. Finally, by calling sp_attach_db plus the corresponding parameters. It should be noted that this method can only be installed without installing the database. Summary This article introduces three different methods to install the database at the installer, and also analyzes the advantages and disadvantages of different methods, users can choose the installation method according to their actual needs. At the same time, by proposing this method, the user can also complete the configuration of the installer is the configuration of the database. Author Blog:
http://blog.9cbs.net/yank/
related articles
Deploy SQL Server Database SQL Server2000's OpenXML Features WMI Series 8: Standardize your own application WMI Series 6: Event Booking and Processing WMI Series 5: Management Object Information Query and Method Access
Comments on this article
Starcraft501 (2004-10-18) Please explain it in detail how to get the path of the file. Finally, by calling sp_attach_db plus the corresponding parameters. The corresponding parameters need to set the path of the installation file Install the file name author's way, please solve, thank you very much!