cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
joel1
Level 3

SQL Script Text Replacement

I am working on an InstallScript installation in InstallShield 2011 Pro. I am using a RESTORE command in the SQL Script to install our application's database (SQL Server 2008 R2 Express is installed as a pre-req).

I can't wrap my head around how to make the path in my SQL script dynamic. I gather I need to use Text Replacement. So on the Text Replacement tab I entered %INSTALLDIR% under 'Find What' and [TARGETDIR] under 'Replace With'.

The following line in the SQL Script fails:

RESTORE DATABASE MyData FROM DISK = '%INSTALLDIR%MyDataSQL.bak' WITH MOVE 'MyData' to '%INSTALLDIR%MyData.mdf', MOVE 'MyData_log' to '%INSTALLDIR%MyData.ldf'

However, if I hard code a path to folder C:\DATA and make sure I install to this folder when I run my install (the BAK file is put in place by the install routine), this restore command works flawlessly.

RESTORE DATABASE MyData FROM DISK = 'C:\DATA\MyDataSQL.bak' WITH MOVE 'MyData' to 'C:\DATA\MyData.mdf', MOVE 'MyData_log' to 'C:\DATA\MyData.ldf'

What am I doing wrong with my Text Replacement here?

Joel
Labels (1)
0 Kudos
(2) Replies
hidenori
Level 17

For InstallScript projects, you need to use the system variable for the Replace With setting. Also, the value of the system variable does not contain a trailing backslash. Therefore, you need to change your SQL script as follows:

RESTORE DATABASE MyData FROM DISK = '%INSTALLDIR%\MyDataSQL.bak' WITH MOVE 'MyData' to '%INSTALLDIR%\MyData.mdf', MOVE 'MyData_log' to '%INSTALLDIR%\MyData.ldf'
0 Kudos
joel1
Level 3

Thanks! That worked!
0 Kudos