Search code examples
wixrollbacksql-scriptssqldb

ExecuteOnInstall and RollbackOnUninstall attributes on SqlScript in WiX


I have the following piece of code in my wxs file for DB.

<Binary Id="binCreateTbl" SourceFile="CREATE_TABLE.sql" />

 <sql:SqlScript BinaryKey="binCreateTbl" Id="script_CreateTbl" ExecuteOnInstall="yes" Sequence="2"/>
 <sql:SqlScript BinaryKey="binCreateTbl" Id="script_CreateTbl1" RollbackOnUninstall="yes" Sequence="1" />

The Create_Table.sql just contains a create table statement with just two simple columns namely ID and Name. When installing the MSI, the table is getting created in the DB, but while uninstalling, the table is not getting removed / dropped. Any idea how to achieve this? I know that including the following piece of code instead of the line with RollbackOnUninstall=yes, then it works. But I want to avoid it. Please help.

<Binary Id="binDropTbl" SourceFile="DROP_TABLE.sql" />
<sql:SqlScript BinaryKey="binDropTbl" Id="script_DropTbl" ExecuteOnUninstall="yes" />

Solution

  • Looks like this is not possible. Since MSI has no way of knowing what is written inside of the sql file, it cannot be rolled back simply using RollbackOnUninstall=yes. There has to be a separate script which will include the code to delete / remove the table during uninstall and it has to be called using ExecuteOnUninstall=yes.