I have a custom action
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action does backup and resolved database. I need to do rollback (drop database) when is canceled installation. I did:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="rollback" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" Before="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
But I was having an error.
If I do like this:
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<CustomAction Id="myActionRollbackId" BinaryKey="myActionRollback" DllEntry="MySimpleAction" Execute="immediate" Return="check" />
<InstallExecuteSequence>
<Custom Action="myActionId" After="InstallInitialize">CHECKBOXCOPYPROP=1</Custom>
<Custom Action="myActionRollbackId" After="myActionId">CHECKBOXCOPYPROP=1</Custom>
</InstallExecuteSequence>
My custom action myActionRollbackId works.
How to run rolback when is canceled installation? Someone can help me?
The custom action which runs on install and does something with the database should be deferred (
Execute='deferred'
). Its corresponding rollback action should beExecute='rollback'
. When you schedule these custom actions, the rollback action should go first.Also, make sure the conditions are set properly.
Installation is always done in transaction. when you launch an installer, it first creates something called installation script which is like a to do list of what it will do while installation. When we set some custom action as Execute="immediate", it gets executed immediately but when we set our action as Execute="deferred", it gets added in the installation script, hence rollback becomes easy for this. Now one thing to note here is that we get access to session in Execute="immediate" mode, but we cannot access session in Execute="deferred" mode. If we try to access session it will give error, which in this case might be the reason for your error...