Go to InstallShield Installation File Creation tips-Additional database

Source: Internet
Author: User

Turn: http://www.cnblogs.com/culturenet/archive/2006/12/19/596930.html

Turn: http://www.cnblogs.com/neilvension/archive/2006/12/20/597806.html

 

Another project is coming to an end recently, but the other party requires installation to be foolish and do not need manual configuration as far as possible. So I just picked up the InstallShield that I haven't used for two or three years. Find InstallShield 12 and start to create the installation package. Because it is a website project, it is not a problem in other aspects, because it was quite skillful when InstallShield 6.2 was used. There are two main aspects: 1. database installation. Because my database contains a lot of stored procedures and initial data, I don't want to initialize it directly using scripts. So I want to package the database files and log files directly in the installation package, and then append them directly during installation. 2. Modify database connection strings and related parameters in the web. config file, such as path-related parameters.

The first point has been explored and summarized. There are two methods: 1. Use a self-defined phrase to declare the SQL syntax, and then use osql.exe for execution.

The function is as follows:

Function number createdatabase (svsqlsvr, svsqlusr, svsqlpwd)
String szwaitline, szwaittxt;
Begin
Szwaittxt = "creating the required database .";
Sdshowmsg (szwaittxt, true );
Delay (2 );

If (g_bwinlogin) then
Szcmdline = "/e/s" + svsqlsvr + "/Q/" Exec sp_attach_db @ dbname = n 'dlbj ', @ filename1 = N' "+ targetdir ^" mydb. MDF ', @ filename2 = N' "+ targetdir ^" dlbj_web_log.ldf '/"";
Else
Szcmdline = "/u" + svsqlusr + "/P" + svsqlpwd + "/s" + svsqlsvr + "/Q/" Exec sp_attach_db @ dbname = n 'dlbj ', @ filename1 = N' "+ targetdir ^" dlbj_web.mdf ', @ filename2 = N' "+ targetdir ^" mydb_log.ldf '/"";
Endif;
// Szcmdline = "/u" + svsqlusr + "/P" + svsqlpwd + "/s" + svsqlsvr + "/Q/" Exec sp_attach_db @ dbname = n 'dlbj ', @ filename1 = N' "+ targetdir ^" dlbj_web.mdf ', @ filename2 = N' "+ targetdir ^" dlbmydb_log.ldf '/"";

If (launchappandwait ("osql.exe", szcmdline, wait) <0) then
MessageBox ("database creation failed! Check that Microsoft SQL Server 2000 is installed in your system. If the problem persists, contact the system supplier! ", Severe );
Endif;
Sdshowmsg (szwaittxt, false );
Szwaittxt = "the system database is being optimized .";
Sdshowmsg (szwaittxt, true );
Delay (2 );
Szcmdline = "/u" + svsqlusr + "/P" + svsqlpwd + "/s" + svsqlsvr + "/Q/" use dlbj; Exec sp_updatestats /"";
If (launchappandwait ("osql.exe", szcmdline, wait) <0) then
MessageBox ("database optimization failed! You can execute use dlbj; Exec sp_updatestats in the SQL query analyzer! ", Severe );
Endif;
Sdshowmsg (szwaittxt, false );

Return 0;

End;

Then execute the following code in onend:

If! Maintenance then

Createdatabase (g_szserver, g_szuser, g_szpassword );
Endif;

G_szserver, g_szuser, and g_szpassword are the server addresses, user names, and passwords obtained through operations on the database settings page (or custom window) in InstallShield.

2. directly create a connection in the installation design view and create a sqlscript, which will be executed directly during installation. In this way, you can know the installation location in advance (this is not possible), so you can directly write the string that can be replaced, and then use the text replacement tab to set the replacement items. Sqlscript:

Use master;
Go
-- Drop database if it exists.
If exists (Select name from SYS. databases where name = 'dmydb ')
Drop database dmydb;
Go
Create Database dlbj on primary
(Filename =
'% Text_to_be_replaced_in_the_file %/dmydb. MDF ')
Log On (filename =
'% Text_to_be_replaced_in_the_file %/dmydb_log.ldf ')
For attach;
Go

Here, % text_to_be_replaced_in_the_file % is the string to be replaced with the installation directory.

Here is something worth noting, for example, the installscript project. On the text replacement tab, the replaced content cannot be directly set to [installdir] or [targetdir]. Instead, it must be set to a replacement variable, for example: <user_data>, that is, replace: % text_to_be_replaced_in_the_file % with: <user_data>, and then execute the following statement in the dlg_sdaskdestpath2: code segment of installscript.

Textsubsetvalue ("<user_data>", targetdir, true );

At that time, it plagued me for a long time and finally found a solution on foreign websites.

For the second point, use the function directly:

Function updatekey (svfilepath, svfindentry, svnewentry)
Number nresult, nvlinenumber;
String webconfigfile, svreturnline;

Begin
// Build the path to the web. config
Webconfigfile = svfilepath ^ "Web. config ";

// Search the file for the key we specify
Nresult = filegrep (webconfigfile, svfindentry, svreturnline, nvlinenumber, restart );
Switch (nresult)
Case 0:
// Since this line normally appears twice in our web. config file, we're
// Checking for the existence of a 2nd match and updating it instead.
// If there is no 2nd match, go ahead and update the one we find.
If (svfindentry = "connectionstring") then
Nresult = filegrep (webconfigfile, svfindentry, svreturnline, nvlinenumber, continue );
If (nresult <0) then
Filegrep (webconfigfile, svfindentry, svreturnline, nvlinenumber, restart );
Endif;
Endif;

// Once we find the key, update (replace) it with our new values
If (fileinsertline (webconfigfile, svnewentry, nvlinenumber, replace) <0) then
// Hmmm we couldn't update the value of the key
MessageBox ("unable to update web. config file.", severe );
Endif;
Case-2:
// File not found
MessageBox ("Web. config file not found.", severe );
Case-4:
// EOF reached
MessageBox (svfindentry + "key not found.", severe );
Default:
// Unknown error
MessageBox ("an unknown error has occurred. The web. config file has not been updated.", severe );
Endswitch;
End;

You can.

My custom simple skin.

Turn: http://www.cnblogs.com/nathan-liu/archive/2006/09/13/502655.html

When creating an installation program, you must create a database on the SQL Server server. In general, InstallShield and wise will let us import the SQL text for creating a database, but this method is sometimes inconvenient, in the following example, we will use these two tools to install MDF files separated from SQL Server to meet our needs.

InstallShield X:
--------------------------
Choose installation designer> server configuration> SQL script ........ s to create a new "SQL connection", and then create a "new script ........ ", edit script ........, in the script box, enter: -- ===================================================== ======
-- Create database for attach
-- ===================================================== ======
Create Database rec2005_test
On Primary (filename = 'C:/DIR/test. MDF ')
For attach
Go then add a replacement in text replacement to replace "C:/DIR" with "[installdir. Of course, the above example may be modified based on the actual situation. This is basically the same in wise.
Related Article

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.