This section is just a supplement.
I. Installation title
According to the previous practice, during the installation process, as shown in figure
The installation title is HxjWebSteup. Such titles and product names cannot be used in actual projects.
Here we need to set the properties of the installation project. Select the HxjWebSetup project and press F4. this is different from the right-click Project attribute. For example:
Let's change the ProductName attribute to Steven hu ProductName.
Let's take a look at the installation process, such:
The installation title and product name have been modified.
2. Additional database
As mentioned in section 2, you can directly attach a database file to create and install a project database.
In fact, we usually use the Enterprise Manager to attach a database. Of course, we can also execute the system stored procedure of the database to complete this operation.
Sp_attach_db storage terms. First, let's take a look at the help document to explain;
Sp_attach_db
Attach the database to the server.
Syntax
Sp_attach_db [@ dbname =] 'dbname'
, [@ Filename1 =] 'filename _ n' [,... 16]
Parameters
[@ Dbname =] 'dbname'
Name of the database to be appended to the server. The name must be unique. The data type of dbname is sysname, and the default value is NULL.
[@ Filename1 =] 'filename _ N'
The physical name of the database file, including the path. The data type of filename_n is nvarchar (260). The default value is NULL. A maximum of 16 file names can be specified. The parameter name starts with @ filename1 and increments to @ filename16. The file name list must contain at least the primary file. The primary file contains the system tables pointing to other files in the database. The list must also contain all the files that are moved after the database is detached.
The following is a specific implementation,
First, put the database file under the app_data folder of the web Project, for example:
Next, modify the code in the installation class as follows:
/// <Summary>
/// Install
/// </Summary>
/// <Param name = "stateSaver"> </param>
Public override void Install (IDictionary stateSaver)
{
Base. Install (stateSaver );
String connectionString = GetConnectionString (null );
Try
{
Using (SqlConnection connection = new SqlConnection (connectionString ))
{
Connection. Open ();
String SQL = "sp_attach_db 'hxjdb', '" + Context. Parameters ["targetdir"]. ToString () + "App_Data/HxjDB_Data.MDF ','"
+ Context. Parameters ["targetdir"]. ToString () + "App_Data/HxjDB_Log.LDF '";
ExecuteSQL (connection, SQL );
// ExecuteSQL (connection, GetResource ("createdatabase. SQL "));
}
}
Catch (Exception ex)
{
MessageBox. Show ("Database Installation failed! \ N database configuration error. Please configure the correct information! \ N "+ ex. Message," error! ");
This. Rollback (stateSaver );
}
} The other items are not changed, and then the package is repackaged.
After installation, the database under the web Project will be attached.
Iii. Uninstall
In the example, there is no problem during installation. When uninstalling or repairing,
/// <Summary>
/// Obtain the database logon connection string
/// </Summary>
/// <Param name = "databasename"> database name </param>
/// <Returns> </returns>
Private string GetConnectionString (string databasename)
{
Return "server =" + Context. Parameters ["server"]. ToString () + "; database =" + (string. IsNullOrEmpty (databasename )? "Master": databasename) + "; User ID =" + Context. parameters ["user"]. toString () + "; Password =" + Context. parameters ["pwd"]. toString ();
} The correct link string cannot be obtained here, Context. parameters ["server"] does not exist any more. Therefore, you need to save the connection string during installation if you want to use it during uninstallation and restoration.
The storage location and method can be stored according to your preferences. After all, the connection string is not confidential and you can easily store it yourself.
To execute the UnInstall method when uninstalling, you need to add HxjDBInstall in the Custom operation of the installation project. For example: