When InstallShield 12 is greater than 6.0, the ms SQL database policy is generated.

Source: Internet
Author: User

The installation package of Pb software is the registry and database, which has been used in the past. The Registry and database must be manually written to the script, which is annoying and often causes errors, because is does not track external programs called, there is no fault tolerance during errors, no error is reported, and the customer cannot generate a database, that is, it cannot. I don't know why it doesn't work.

This is how to generate a database during InstallShield 6.3.

# I nclude "ifx. H"
// Nnll add global variables
Bool bvtype; // record the installation type and whether it is a server
String szmyse, szmyna, and szmypa; // SQL Server Name, user name, and logon Password
// Nnll added

In function onfirstuibefore (), add two pairs of boxes. The first is selecttype, which is used to select whether to install the server program. If it is to install the server program, enter the second pair of boxes dlg_sdshowdlgedit3, the user is required to enter the machine name, user name, and password for database installation.

// Add nnll to determine whether the server or workstation is installed
Selecttype:
Szmsg = "select the computer to install :";
Bvcheck1 = true;
Bvcheck2 = false;
Bvtype = true;
Nresult = askoptions (exclusive, szmsg, "server", bvcheck1, "workstation", bvcheck2 );
If (nresult = back) goto dlg_sdlicense2;
If bvcheck2 = true then
// Workstation, registry entry Server = 0
Bvtype = false;
Else
// Server, registry entry Server = 1
Bvtype = true;
Endif;

If bvtype = true then
Dlg_sdshowdlgedit3:
Szmsg = "Enter the server name or IP address of the server, and the username and password for logging on to the Database ";
Sztitle = "Enter Server Information ";
Szfield1 = "server name ";
Szfield2 = "User Name ";
Szfield3 = "password ";
Nresult = sdshowdlgedit3 (sztitle, szmsg, szfield1, szfield2, szfield3, szmyse, szmyna, szmypa );
If (nresult = back) then
Goto selecttype;
Else
If (szmyse = "") then
MessageBox ("Enter the server name or IP address", information );
Goto dlg_sdshowdlgedit3;
Elseif (szmyna = "") then
MessageBox ("Enter the database Login User Name", information );
Goto dlg_sdshowdlgedit3;
Elseif (szmypa = "") then
MessageBox ("Enter the database logon password", information );
Goto dlg_sdshowdlgedit3;
Endif;
Endif;
Endif;
// Nnll modified

Add the onend function to generate a database

// Nnll starts adding a function
Function onend ()
String sztemp;
String szfilena;
String szwaitline, szwaittxt;
Begin
If! Maintenance then // non-maintenance code, that is, only executed during installation
// Modify the INI File
Szfilena = targetdir + "// config. ini ";
Sztemp = "logpass =" + szmypa;
Fileinsertline (szfilena, sztemp, 3, replace );
Sztemp = "servername =" + szmyse;
Fileinsertline (szfilena, sztemp, 4, replace );
Sztemp = "logid =" + szmyna;
Fileinsertline (szfilena, sztemp, 5, replace );

// Modify nnll. SQL
Szfilena = targetdir + "// mydata // nnll. SQL ";
Sztemp = "create database [wlpalestra] On (name = n' homelandj _ data', filename = N'" + targetdir + "// mydata // homelandj. MDF ', size = 5, filegrowth = 10%) log on (name = n' homelandj _ log', filename = N' "+ targetdir +" // mydata // homelandj_log.ldf ', filegrowth = 10% )";
Fileinsertline (szfilena, sztemp, 1, replace );
Sztemp = "from disk = '" + targetdir + "// mydata // nnll. Bak '";
Fileinsertline (szfilena, sztemp, 44, replace );

// Process the database
If bvtype then
// MessageBox ("server", information );
Szwaittxt = "Creating" + @ product_name + "required database ....";
Sdshowmsg (szwaittxt, true );
Delay (2 );
// Szdomainline = "-U" + szmyna + "-P" + szmypa + "-s" + szmyse + "-Q/" Exec sp_attach_db n 'gbwz ', n' "+ targetdir ^" // wzgldata // gbwz_data.mdf '/"";
Szw.line = "-U" + szmyna + "-P" + szmypa + "-s" + szmyse + "-e-I/" "+ targetdir +" // nnll. SQL /"";
// MessageBox (szcmdline, information );
If (launchappandwait ("osql.exe", szcmdline, wait) <0) then
MessageBox ("database creation failed! Confirm that Microsoft SQL Server 2000./N has been installed in your system. If the problem persists, contact the system supplier! ", Severe );
Endif;
Endif;
Endif;
End;

Execute the SQL file from the red "// slave to generate the database

This method is very troublesome, right?

Now you can use installshield11.5 to generate a database conveniently.

Database generation in three steps:

1. Write an SQL script. You must write an SQL script to generate a database.

2. Choose server configuration> SQL scripts and set database connection and script information.

① Right-click SQL scripts and new SQL connection to add a database connection, for example:


The catalog name, loginid, and password set here are default values. This interface is generated during installation. You can modify them by yourself:

This interface is equivalent to the dlg_sdshowdlgedit3 dialog box that collects database information in InstallShield 6.3. It is automatically generated by is and is automatically generated by the next step in this dialog box, is used to check the connection status of the database

② Right-click sqlconnection, import script files, add an SQL script, select the text replacement tag, and set the database path here,

The setting here is equivalent to the manual replacement in the onend function in InstallShield 6.3. Here I Replace "D:/" with "<targetdir>/database /", in the SQL script, I wrote two files of the database in D:/. Now I want to generate the database in the database folder under the user's installation directory.

3. Modify the script and add the installation method. If the user installs the server program and generates the database, if the user installs the client program, skip the database installation.

// Add nnll to determine whether the server or workstation is installed
Selecttype:
Szmsg = "select the computer to install :";
Bvcheck1 = true;
Bvcheck2 = false;
Bvtype = true;
Nresult = askoptions (exclusive, szmsg, "server", bvcheck1, "workstation", bvcheck2 );
If (nresult = back) goto dlg_sdlicense2;
If bvcheck2 = true then
// Workstation, registry entry Server = 0
Bvtype = false;
Else
// Server, registry entry Server = 1
Bvtype = true;
Endif;
// Nnll modified

If bvtype = true then
Dlg_sqlserver: // database connection
Nresult = onsqlserverinitialize (nresult );
If (nresult = back) goto dlg_sdfeaturetree;

Dlg_objdialogs: // Test Database Connection
Nresult = showobjwizardpages (nresult );
If (nresult = back) goto dlg_sqlserver;
Endif;

Check that installshield12 generates a database in this way, which is much easier than 6.3, right?

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.