PDA

View Full Version : Custom SQL Script (MDF/LDF location & size)



Ron Petty
06-03-2005, 11:09 AM
Good Morning (Evening),
I am trying to do the folllowing, my SQL script has some text that needs to be replaced before it is ran. Only after asking the user.

CREATE DATABASE [C2DB] ON (NAME = N'C2DB_dat', FILENAME = N'%MDFLOCATION%\DB.mdf' , SIZE = %MDFSIZE%, FILEGROWTH = 10%) LOG ON (NAME = N'DB_log', FILENAME = N'%LDFLOCATION%\DB.ldf' , SIZE =%LDF SIZE%, FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO

I want to ask the user for the install location and the size of the MDF and LDF files. I have to do this becuase the location changes based on the user, and users of MSDE have a smaller size then of SQL Server users. Here is my failed approach...

1) In OnFirstUIBefore I added some dialogs to ask for this information before OnSQLServerInitialize is called. I made the variables global (outside of the function) for the results.
2) Under "Installation Designer/Server Configuration/SQL Scripts", I added my script.
3) Under text replacement I have
%MDFLOCATION% <NEWMDFLOCATION>
%LDFLOCATION% <NEWLDFLOCATION>
..size..
..size..

I assume I am doing something wrong with NEWMDFLOCATION/LDFLOCATION, I saw an example where someone did <INSTALLDIR> as the replacement text.
Basically it replaces %..% with <WHATIHADINTEXTREPLACEMNT AND NOT MY VARIABLE>. Is the syntax wrong here for using variables, or can you?

Is it possible to get your own values into the text replacement? If not, can you point out the location of where InstallShield does all this SQL magic, and maybe I can insert my something there. I have yet to see where or how the sql file got attached under the "sql scripts" wizard.

Here is my rul file..


//===========================================================================
//
// File Name: Setup.rul
//
// Description: Blank setup main script file
//
// Comments: Blank setup is an empty setup project. If you want to
// create a new project via. step-by step instructions use the
// Project Assistant.
//
//===========================================================================

// Included header files ----------------------------------------------------
#include "ifx.h"

string szMDF;
string szLDF;
string NEWMDFLOCATION;
string NEWLDFLOCATION;
string MDFSIZE;
string LDFSIZE;

//---------------------------------------------------------------------------
// OnFirstUIBefore
//
// First Install UI Sequence - Before Move Data
//
// The OnFirstUIBefore event is called by OnShowUI when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIBefore()

....
//missing Size dialog, same though

nResult = SdShowDlgEdit2(szTitle, szMsg, "MDF:", "LDF:", szMDF, szLDF);
NEWMDFLOCATION=szMDF;
NEWLDFLOCATION=szLDF;

nResult = OnSQLServerInitialize( nResult );
if( nResult = BACK ) goto Dlg_SdFeatureTree;

return 0;
end;



Thanks for the help!
Ron

Ron Petty
06-03-2005, 11:27 AM
I copied this from another reply, it works. Thanks hidenori!

hidenori hidenori is offline
Mega User (200+ Posts)

Join Date: Oct 2001
Posts: 302
In the InstallScript project type, you can use the InstallScript's Text Substitutions. Here is an sample InstallScript code to set a value to the Text Substitution named, <MYTEXTSUB>:

TextSubSetValue ( "<MYTEXTSUB>", "First Text Sub", TRUE );

You can use it in the Text Replacement tab as follows:

Find What: foo
Replace With: <MYTEXTSUB>

Hope this helps.
Reply With Quote

Ron Petty
06-03-2005, 11:28 AM
Maybe someone at Installshield could update the instructions on the sql page on how to use this function to get text. I assume the old dogs know how to do this, but I am new to all of this, and sort of confused.

Thanks.
Ron

olegkap
06-03-2005, 02:25 PM
I had similar problem,
You can do as follow :
In the text replacment tab define:
%MDFSIZE% - <MDFSIZE>
etc

Then after you asking user for location and lets say you place it in szMDFSize should do the following.
TextSubSetValue ("<MDFSIZE>", szMDFSize , TRUE );

So whats going to happend at a run time it will automaticlly pick up the values that you "register" to be replaces.

You can investigate more about TextSubSetValue functions, its pretty cool,
I dont know if its documented, since I am new with it and have no books so far.

Oleg.



Good Morning (Evening),
I am trying to do the folllowing, my SQL script has some text that needs to be replaced before it is ran. Only after asking the user.

CREATE DATABASE [C2DB] ON (NAME = N'C2DB_dat', FILENAME = N'%MDFLOCATION%\DB.mdf' , SIZE = %MDFSIZE%, FILEGROWTH = 10%) LOG ON (NAME = N'DB_log', FILENAME = N'%LDFLOCATION%\DB.ldf' , SIZE =%LDF SIZE%, FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO

I want to ask the user for the install location and the size of the MDF and LDF files. I have to do this becuase the location changes based on the user, and users of MSDE have a smaller size then of SQL Server users. Here is my failed approach...

1) In OnFirstUIBefore I added some dialogs to ask for this information before OnSQLServerInitialize is called. I made the variables global (outside of the function) for the results.
2) Under "Installation Designer/Server Configuration/SQL Scripts", I added my script.
3) Under text replacement I have
%MDFLOCATION% <NEWMDFLOCATION>
%LDFLOCATION% <NEWLDFLOCATION>
..size..
..size..

I assume I am doing something wrong with NEWMDFLOCATION/LDFLOCATION, I saw an example where someone did <INSTALLDIR> as the replacement text.
Basically it replaces %..% with <WHATIHADINTEXTREPLACEMNT AND NOT MY VARIABLE>. Is the syntax wrong here for using variables, or can you?

Is it possible to get your own values into the text replacement? If not, can you point out the location of where InstallShield does all this SQL magic, and maybe I can insert my something there. I have yet to see where or how the sql file got attached under the "sql scripts" wizard.

Here is my rul file..


//===========================================================================
//
// File Name: Setup.rul
//
// Description: Blank setup main script file
//
// Comments: Blank setup is an empty setup project. If you want to
// create a new project via. step-by step instructions use the
// Project Assistant.
//
//===========================================================================

// Included header files ----------------------------------------------------
#include "ifx.h"

string szMDF;
string szLDF;
string NEWMDFLOCATION;
string NEWLDFLOCATION;
string MDFSIZE;
string LDFSIZE;

//---------------------------------------------------------------------------
// OnFirstUIBefore
//
// First Install UI Sequence - Before Move Data
//
// The OnFirstUIBefore event is called by OnShowUI when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIBefore()

....
//missing Size dialog, same though

nResult = SdShowDlgEdit2(szTitle, szMsg, "MDF:", "LDF:", szMDF, szLDF);
NEWMDFLOCATION=szMDF;
NEWLDFLOCATION=szLDF;

nResult = OnSQLServerInitialize( nResult );
if( nResult = BACK ) goto Dlg_SdFeatureTree;

return 0;
end;



Thanks for the help!
Ron