cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Swilks
Level 5

SQL Scripts

Hello All,

I am new to Installshield so not sure whether this is possible.

Can you run custom actions in between SQL scripts executing ?
As far as I can see the SQL scripts run together ordered by the order property in that table.

I am wanting to run a custom action between two of the SQL scripts but not sure how I separate the SQL routines to run individually and not as a group.

Any help greatly appreciated.

regards
Shaun
Labels (1)
0 Kudos
(5) Replies
hidenori
Level 17

That is not possible. I am wondering why you need to run a custom action between SQL scripts.
0 Kudos
Swilks
Level 5

Thanks for that confirmation. In the meantime I worked out a way to do what I wanted from within a SQL script itself.

Just the detail to curb your interest....
The install package installs an MDF and attachs it at the end of the process.
The problem is however that the database may exist on the detsination server and must be dropped first.

As this is the case the first SQL statement run is a DROP database (which removes MDF files in the database folder). After the database is dropped I need to move the new MDF file into the data folder before attaching it.
Ive managed to do the move using the xp_cmdshell extended stored procedure. Bu this was going to be the custom action I had running between SQL scripts.

Thansk again for the confirmation.
0 Kudos
hidenori
Level 17

I think that you should be able to accomplish your requirement using a single SQL script in the SQL Scripts view without having another custom action as follows:

[Code]IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'TestDatabase')
DROP DATABASE TestDatabase
GO

EXEC xp_cmdshell 'copy "C:\Test1\TestDatabase.mdf" "C:\Test2\TestDatabase.mdf"'
GO

EXEC xp_cmdshell 'copy "C:\Test1\TestDatabase_log.ldf" "C:\Test2\TestDatabase_log.ldf"'
GO

CREATE DATABASE [TestDatabase] ON (NAME = N'TestDatabase', FILENAME = N'C:\Test2\TestDatabase.mdf' , SIZE = 3, FILEGROWTH = 1) LOG ON (NAME = N'TestDatabase_log', FILENAME = N'C:\Test2\TestDatabase_log.ldf' , SIZE = 1, FILEGROWTH = 10%) FOR ATTACH
GO
[/Code]
0 Kudos
Swilks
Level 5

Yes I already have got this working along the lines you detailed.

Just provided that detail as you were wondering why I needed a custom action between scripts. Turns out I found the work around.
The xp_cmdshell procedure is an interesting one given you have to enable it and it forces the SQL connection to a user part of the sysadmin role in SQL Server.

Thats again
0 Kudos
ch_eng
Level 7

An FYI for anyone looking to certify their software via the Microsoft "Works with SQL Server 2008 Test": it is required that xp_cmdshell be turned off.
0 Kudos