Web program packaging method

Source: Internet
Author: User
Tags microsoft website visual studio installer

Use vs2005 to create an installation package
1. Select the "other project types"-> "setup and deployment" node in the tree on the left of the "new project" dialog box, and select "Web Setup project" on the right ".
 
2. In Solution Explorer, right-click solution and choose add> existing web site to add the folder of the compiled web site to solution.
 
If you add a website compiled with aspnet_compiler, the following prompt box may appear. Click "yes.
 

3. Add a new "class library" named "createdb" to create a database.
 

Delete the default generated "class1.cs". Right-click the project and choose "add"> "new item". In the displayed dialog box, select "Installer class" and click "OK.
 
Add the following code to the class:
Private void executesql (string connectionstring, string databasename, string SQL)
{
Sqlconnection = new sqlconnection (connectionstring );
Sqlcommand = new sqlcommand (SQL, sqlconnection );
Try
{
Sqlcommand. Connection. open ();
Sqlcommand. Connection. changedatabase (databasename );
Sqlcommand. executenonquery ();
}
Catch (exception)
{
Throw exception;
}
Finally
{
Sqlcommand. Connection. Close ();
}
}

Public override void install (system. Collections. idictionary statesaver)
{
String Server = This. Context. Parameters ["server"];
String database = This. Context. Parameters ["dbname"];
String user = This. Context. Parameters ["user"];
String Password = This. Context. Parameters ["PWD"];
String targetdir = This. Context. Parameters ["targetdir"];

Try
{
String connectionstring = string. Format ("Data Source = {0}; user id = {1}; Password = {2}; persist Security info = false; packet size = 4096 ",
Server, user, password );

// Create DB
Executesql (connectionstring, "Master", "create database" + database );

// Set User
String setuserstring = "sp_addlogin 'printeryerp ', 'printeryerp', 'printeryerp '";
String setaccessstring = "sp_grantdbaccess 'printeryerp '";
String setrole = "sp_addrolemember 'db _ owner', 'printeryerp '";

// Create new user login
Try
{
Executesql (connectionstring, "Master", setuserstring );
}
Catch {}

// Set default database
Try
{
Executesql (connectionstring, "printeryerp", setaccessstring );
}
Catch {}

// Set read role
Try
{
Executesql (connectionstring, "printeryerp", setrole );
}
Catch {}

// Create table, store produce ......
Process osqlprocess = new process ();
Osqlprocess. startinfo. filename = targetdir + "osql.exe ";
Osqlprocess. startinfo. arguments = string. format ("-U {0}-P {1}-s {2}-d {3}-I {4} createdb. SQL ",
User, password, server, database, targetdir );
Osqlprocess. startinfo. windowstyle = processwindowstyle. hidden;
Osqlprocess. Start ();
Osqlprocess. waitforexit ();
Osqlprocess. Close ();

// Add data
Osqlprocess. startinfo. arguments = string. format ("-U {0}-P {1}-s {2}-d {3}-I {4} insertdata. SQL ",
User, password, server, database, targetdir );
Osqlprocess. startinfo. windowstyle = processwindowstyle. hidden;
Osqlprocess. Start ();
Osqlprocess. waitforexit ();
Osqlprocess. Close ();
}
Catch (exception)
{
Throw exception;
}

Try
{
String configfile = targetdir + "/Web. config ";
If (! File. exists (configfile ))
{
Throw new installexception ("the configuration file is not found. ");
}

Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (configfile );

GC. Collect ();
File. Delete (configfile );
GC. Collect ();

Foreach (xmlnode in xmldoc ["configuration"] ["connectionstrings"]. childnodes)
{
If (xmlnode. Name = "add ")
{
If (xmlnode. attributes ["name"]. value = "dbconnection ")
{
Xmlnode. attributes ["connectionstring"]. value = string. format ("Data Source = {0}; initial catalog = {1}; persist Security info = true; user id = printeryerp; Password = printeryerp ",
Server, database );
}
If (xmlnode. attributes ["name"]. value = "usermanageservicesconnection ")
{
Xmlnode. attributes ["connectionstring"]. value = string. format ("Data Source = {0}; initial catalog = {1}; persist Security info = true; user id = printeryerp; Password = printeryerp ",
Server, database );
}
}
}
Xmldoc. Save (configfile );
}
Catch (exception)
{
Throw exception;
}
}
4. Right-click the "Web Setup project" project, choose "add"> "project output", select "createdb", select "primary output", and click "OK. Repeat the preceding action to select the added web site, select "content Files", and click OK.

 

5. Right-click the "Web Setup project" project and choose "add"> "file" to add the createdb. SQL script for creating database tables, stored procedures, and views. Repeated. The script insertdata. SQL for adding basic data to the data table is added. Replay and add the program osql.exe.
6. Right-click the "Web Setup project" project and choose "add"> "Merge Module". In the displayed dialog box, select "vc_user_crt71_rtl_x86 _ ---. MSM" and click OK. The reason for testing the vcpus on a clean machine is that the osql.exe program needs this library.
7. Right-click the "Web Setup project" project and select "properties". In the displayed dialog box, you can set the properties of some installation programs. Click prerequisites. In the displayed dialog box, select. NET Framework 2.0 and Windows Installer 3.1, and select download prerequisites from the same location as my application ". In this way, these components and applications can be packaged together and automatically detected and installed during installation. If the computer to be deployed has not been installed with the latest patch, there is no "Windows Installer 3.1". Without this component, ". NET Framework 2.0" cannot be installed.

8. right-click the "Web Setup project" project, choose "View"> "Custom Actions", and right-click the node "Install" on the tree chart that appears, select "add M actions ". In the displayed dialog box, select "Web Application folders" in "look in", select "primary output from createdb (active)" below, and click "OK.
 

9. right-click the "Web Setup project" project, choose "View"> "User Interface", and right-click the child node "start" of the "Install" tree chart node, select "add dialog". In the displayed dialog box, select "textboxes ()".
 
Right-click the newly added node "textboxes (a)", select "properites window", and set the edit * property to "mmtexta1" and "customtexta2" in sequence ", "mmtexta3" and "customtexta4 ".

10. right-click the created "primary output from createdb (active)" node and select "Properties window ", set the "customactiondata" attribute to "/dbname = [customtexta1]/Server = [customtexta2]/user = [customtexta3]/Pwd = [customtexta4]/targetdir =" [targetdir]/" ".

Next, compile the entire solution and generate two folders and two files in the output directory.
The two folders contain the installation packages of. NET Framework 2.0 and Windows installer3.1 respectively. The two files are classified as (.msi.msiand setup.exe. If you want to install it, execute setup.exe.

To successfully install and use the Crystal Report on a "clean" machine, follow these steps:

1) create a "installation and deployment project" --> "Installation Wizard"
(2) Select the project type (here, select "Create an installer for Windows Applications") --> next
(3) Select the file to be included: deploy and use Crystal Reports for Visual Studio. NET 2003 program, you need to add the merging module (right-click the top node of the tree in Solution Explorer --> Add ).
Crystal_database_access2003.msm
Crystal_database_access2003_enu.msm
Crystal_managed2003.msm
Crystal_regwiz2003.msm
Vc_user_crt71_rtl_x86 _ ---. MSM
Vc_user_stl71_rtl_x86 _ ---. MSM
You can find the replaced merging module in the 'C:/program files/common files/merge modules 'folder.
(4) open solution --> right-click the properties of crystal_regwiz2003.msm, and fill in "license key" in "mergemouduleproperties: * ************************** (this is the registration code used to generate the crystal report. !)
(5) generate a solution
If there is no step 4, A keycodev2.dll or invalid password error will be prompted when you execute the print report.
In the above steps, if your "clean" machine is installed with a crystal report, you can do it here.
If you do not want to attach a crystal report to a "clean" machine, follow these steps:
In "add project output group", select "primary output" and click "OK ".
All dependencies are automatically added, such as dotnetfxredist_x86_enu.msm and dotnetcrystalreports. MSM.
2. to exclude dotnetcrystalreports. MSM from the project, right-click the module in Solution Explorer and choose exclude ".
3. In Solution Explorer, right-click the installation project, point to "add", and then click "Merge Module ".
4. In the "add module" dialog box, select the following modules to be added to the installation project, and click "open ":
Reportengine. MSM,
Crnetruntime. MSM
License. MSM
Mapping. MSM (optional. When geographic maps are used in the report)
5. In Solution Explorer, right-click the license. MSM file and select "properties ".
6. In the "properties" window, expand mergemoduleproperties and enter a valid license key in the "license key" attribute box.
Note: The license key must be provided whenever the Crystal Reports application is deployed.
7. From the "generate" menu, select "generate solution" to generate the application
If the preceding steps are not completed, the error "load crpe32.dll failed" is displayed.
Modules used: http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9netmergemodules_chs.zip.asp
Http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9netredist_chs.zip.asp
Http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9rdcmergemodules_chs.zip.asp
If Windows 98 is installed on your machine, the following steps will generate a "load report failed" (crqe. dll) error.
Reports can be loaded on some Win98 clients. When some Win98 clients load reports, the message "load report failed" is displayed because of the crqe required for the crystal report to run. the DLL is incorrectly registered in the client system because it is ATL. the dll version is incorrect (the correct version number in Windows 98/me should be 3.0.8449 ).
There are two solutions:
1. It is no wonder that some clients are running normally when ie6.0 is installed on the client.
2. Add the ATL. MSM module to the installation project. ATL. MSM is part of Visual Studio installer 1.1. You can go to the Microsoft website http://msdn.microsoft.com/vstudio/downloads/tools/vsi11/download.aspxto download the program.
At this point, the packaging is basically complete. Note:
If you are using the push mode of the crystal report, you do not need to set the login information, but you need to write: obj. setdatasource (this. DS. tables ["tablename"]); if you write obj. setdatasource (this. DS.
If you are using the PULL mode of the crystal report, you must write the login information:
Crreportdocument = new oraclereport ();
// Set the crconnectioninfo with the current values stored in the report
Crconnectioninfo = crreportdocument. database. Tables [0]. logoninfo. connectioninfo;
/* Populate the connectioninfo objects properties with the appropriate values
The servername, user ID, password and databasename. However, since Oracle
Works on schemas, Crystal Reports does not recognize or store a databasename.
Therefore, the databasename property must be set to a blank string .*/
Crconnectioninfo. databasename = "";
Crconnectioninfo. servername = "your server name ";
Crconnectioninfo. userid = "Your User ID ";
Crconnectioninfo. Password = "your password ";
// Set the crdatabase object to the report's database
Crdatabase = crreportdocument. database;
// Set the crtables object to the tables collection of the report's ddtabase
Crtables = crdatabase. tables;
// Loop through each table object in the tables collection and apply the logon info
// Specified ealier. Note this sample only has one table so the loop will only execute once
Foreach (Table crtable in crtables)
{
Crtablelogoninfo = crtable. logoninfo;
Crtablelogoninfo. connectioninfo = crconnectioninfo;
Crtable. applylogoninfo (crtablelogoninfo );

// If you wish to change the schema name as well, you will need to set Location Property as follows:
// Crtable. Location = "<new schema Name>." + crtable. Name;
}
// Set the reportsource of the crystalreportviewer to the stronugly typed report stored in the project
Crystalreportviewer1.reportsource = crreportdocument;
Note the following:
If you use a subreport, you must process it:
// Go through each sections in the main report and identify the subreport by name
Crsections = crreportdocument. reportdefinition. sections;

Foreach (section crsection in crsections)
{
Crreportobjects = crsection. reportobjects;
// Loop through all the report objects to find all the subreports
Foreach (reportobject crreportobject in crreportobjects)
{
If (crreportobject. Kind = reportobjectkind. subreportobject)
{
// You will need to typecast the reportobject to a subreport
// Object once you find it
Crsubreportobject = (subreportobject) crreportobject;

// Open the subreport object
Crsubreportdoc = crsubreportobject. opensubreport (crsubreportobject. subreportname );
// Once the correct subreport has been located pass it
// Appropriate dataset
If (crsubreportdoc. Name = "firstsub ")
{
// Crsubreportdoc. database. Tables [0]. setdatasource (DS );
Crsubreportdoc. setdatasource (DS );
}
}
}
}
Crystalreportviewer1.reportsource = crreportdocument;

Similarly, crsubreportdoc. setdatasource (DS); changed to crsubreportdoc. setdatasource (Ds. Tables ["tablename"]);

_______________________________________________________________________

After packaging according to the preceding method, the following error message is displayed when you run the generated Installer:
An error occurred while establishing a connection to the server. When you connect to SQL Server 2005, the default setting does not allow remote connection to SQL Server may cause this failure. (Provider: named pipeline provider, error: 40-unable to open the SQL server connection)

Why?

Right-click the "Web Setup project" project and select "properties". In the displayed dialog box, you can set the properties of some installation programs. Click prerequisites. In the displayed dialog box, "Crystal Reports. net framework2.0 "and" SQL Server 2005 express edittion ". Do you need to add the Crystal Report and MSDE to these two statements?
_______________________________________________________________________

Actually, it's very simple. Why is it so complicated?
1. Create an installation and deployment project in an existing web project.
2. Package the files to be packaged according to the specified directory
For example, put the "Project name. dll" file in the DEBUG directory.
Other files are also placed according to the corresponding directory.
3. For a publishing program, pack the file with the aspx Suffix of the page file.
If you only package the source program, we recommend that you add all files.
4. Final generation,
5. Run the newly generated Installation File for installation testing to see if any files are missing.
 

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.