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

Conditionally run SQL scripts during uninstall

Conditionally run SQL scripts during uninstall

Summary

This article explains how to conditionally run SQL scripts during uninstall.

Synopsis

The SQL Scripts are explicitly tied to component states. The condition that you are setting in the SQL view is actually the condition on the underlying component. Therefore, the condition does not affect during uninstall as Windows Installer removes all installed components regardless of their conditions. If you would like to conditionally run SQL scripts during uninstall, you need to add the conditional statement to your scripts.

Discussion

The following instruction illustrates how to create a setup that will drop the 'MyDB' database during uninstall only when the SQL_SCRIPTS_DROPDB property is set to '1' .

1. Create a new Basic MSI project.
2. Navigate to SQL Scripts view.
3. Add a new connection and a SQL script.
4. Click the Runtime tab and check "Run Script During Uninstall" and uncheck "Run Script During Install".
5. Click the Script tab and add the following statements:
If ?%SQL_SCRIPTS_DROPDB%? = ?1?
BEGIN
DROP DATABASE [MyDB]
END
6. Click Text Replacement tab and add the following entry
Find What: %SQL_SCRIPTS_DROPDB%
Replace With: [SQL_SCRIPTS_DROPDB]
7. Build a project release.

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Dec 31, 2008 05:19 PM
Updated by: