This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- SQL Script Text Replacement
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jan 26, 2011
05:07 PM
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
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
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jan 26, 2011
05:21 PM
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'
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Jan 31, 2011
11:07 AM
Thanks! That worked!