Thanks for the update Joe, good to see it worked.

I had not considered the issue of releasing the database, you may find
this is because the SqlString is associated with the database itself.
But it will also make sure any users of the database are kicked off.

One alternate to using the USE [Master] statement is something like what
we do with backing up the database before upgrade.   The Database ID
"sqlserver_Master" is not defined as part of a component, so it is not
managed by the installer (ie installed or uninstalled) it just a refen

The strings that then manipulate our target database actually reference
this database, but being under the target database component they only
get run with the database component.  (again this is in WIX Version 2).

                <SqlDatabase Id="sqlserver_Master" Database="master"
Server="[BAYDBSERVER]" Instance="[BAYDBINST]"/>
                <DirectoryRef Id="TARGETDIR">
                        <Component Id="CreateDB"
Guid="F791A6C2-1281-168B-0021-001143F0301B" DiskId="1">
                                <Condition><![CDATA[(Not BAYUPGRADELIST)
and 1]]></Condition>
                                <!-- Clean up for install only failure
-->
                                <SqlString Id="CleanupOnInstallFail"
SqlDb="sqlserver_Master" RollbackOnInstall="yes" ContinueOnError="no"
SQL="drop database [BAYAPPDB]" Sequence="19"/>
                                <!-- Set Single User for Backup and
MultiUser if rolling back -->
                                <SqlString Id="MultiUserOnRollBack"
SqlDb="sqlserver_Master" RollbackOnReinstall="yes"
RollbackOnInstall="no" ContinueOnError="no" SQL="alter database
[BAYAPPDB] set MULTI_USER" Sequence="20"/>
                                <SqlString Id="SingleUserOnStart"
SqlDb="sqlserver_Master" ExecuteOnInstall="no" ExecuteOnReinstall="yes"
ContinueOnError="no" SQL="alter database [BAYAPPDB] set SINGLE_USER With
Rollback Immediate" Sequence="21"/>
                                <SqlString Id="BackupOnStart"
SqlDb="sqlserver_Master" ExecuteOnInstall="no" ExecuteOnReinstall="yes"
ContinueOnError="no" SQL="backup database [BAYAPPDB] to
disk='[BAYBACKUPFOLDER][BAYAPPDB].bak' with INIT" Sequence="30"/>
                                <!-- Restore on minor upgrade rollback
-->
                                <!-- Restore on minor upgrade rollback
-->
                                <SqlString Id="RestoreOnRollBack"
SqlDb="sqlserver_Master" RollbackOnReinstall="yes" ContinueOnError="no"
Sequence="40" SQL="
                                
          -- This sequence restores the database if there is a failure
          alter database [BAYAPPDB] set SINGLE_USER With Rollback
Immediate
          drop database [BAYAPPDB]
          restore database [BAYAPPDB] from
disk='[BAYBACKUPFOLDER][BAYAPPDB].bak'

          "/>

-----Original Message-----
From: Joe Osman [mailto:joe.os...@tait.co.nz] 
Sent: Wednesday, 18 February 2009 10:54 AM
To: General discussion for Windows Installer XMLtoolset.
Subject: Re: [WiX-users] sql:SqlDatabase drops database on major upgrade

Thanks Michael,
I have it working now though I had make a few modifications in your
code: the REMOVE property was set to ALL on a major upgrade as well as
on uninstall so I added another property to check whether it's a product
upgrade - I only want to drop the database on an uninstall and nor on an
upgrade.

Here is the code that I add to the SqlString element:

use [master]
IF ('[REMOVE]' = 'ALL' AND '[KMFUNINSTALL]' = 'KMFUNINSTALL') BEGIN
    ALTER DATABASE $(var.DataBaseName)
    SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    DROP DATABASE $(var.DataBaseName)
END

<CustomAction Id="CheckKMFUninstall" Property="KMFUNINSTALL" 
Value="KMFUNINSTALL"/>

In the  execute  sequence:
<Custom Action="CheckKMFUninstall" After="InstallInitialize">Installed
AND NOT UPGRADINGPRODUCTCODE</Custom>

Michael Osmond wrote:
> Joe,
>  
> My appologies, I was not carefull.  If you put that SQL code in a
SQLString element (not SQLScript), then it is treated like a formatted
MSI string, so the [REMOVE] gets expanded to the REMOVE property before
execution.   My understanding is that REMOVE is set to ALL for an
uninstall.
>  
> Michael
>
> ________________________________
>
> From: Joe Osman [mailto:joe.os...@tait.co.nz]
> Sent: Tue 17/02/2009 12:26 PM
> To: General discussion for Windows Installer XMLtoolset.
> Subject: Re: [WiX-users] sql:SqlDatabase drops database on major 
> upgrade
>
>
>
> Hi Michael,
> In your answer are you referring to WIX V2 or WIX V3?
> I am using V3 and when I tried to reschedule the custom action 
> DeleteExistingProduct  I got the error message:  Unresolved reference 
> to symbol 'CustomAction:DeleteExistingProduct' .
>
> In your second comment you are saying that the script should run on 
> ExecuteOnUninstall. Based on your suggestion I've created the 
> following sql script:
> USE [master]
> GO
> IF ('[REMOVE]' = 'ALL')
> BEGIN  
>     DROP DATABASE MyDataBase
> END
>
> but the database doesn't get removed on uninstall. How can the sql 
> script determine the value of [REMOVE] on uninstall?
>
> Thank you.
>
> Michael Osmond wrote:
>   
>> Hello Joe,
>>
>> I've been in a similar situation.  The possible solutions I am aware
of:
>>
>> 1.  If you schedule the DeleteExistingProduct action at the end of 
>> the install (I think after the InstallFinalise), my understanding is 
>> that the install should calculate that there still is a count of one 
>> on the database component and not remove it.  For other reasons I 
>> don't use this with mine.
>>
>> 2.  Don't use the DropOnUnistall.  Set the database as 
>> CreateOnInstall=y ContinueOnError=y and then have an SQL Script that 
>> is set to run ExecuteOnUninstall that drops the database.  You could 
>> then put an MSI condition into the script eg:  IF ('[REMOVE]' = 
>> 'ALL') drop database [DBNAME].  It gives you a little more control.
>>
>> For the books.  Because of the nature of data in our server 
>> application, our uninstall does not delete the database at all, the 
>> user must manually (and hence knowingly) drop the database.
>>
>> PS:  Something to check.  Test what happens if there is a rollback 
>> during (or after) the SQL Install.  My experience was that the 
>> rollback (because this is technically an install of a new database 
>> component) would do the rollback by droping the database.  (I am 
>> still on WIX V2 and have a slightly modified version of the SQL
Custom Actions).
>>
>> Mihael
>>
>> -----Original Message-----
>> From: Joe Osman [mailto:joe.os...@tait.co.nz]
>> Sent: Monday, 16 February 2009 12:14 PM
>> To: General discussion for Windows Installer XMLtoolset.
>> Subject: [WiX-users] sql:SqlDatabase drops database on major upgrade
>>
>> I want to have my database dropped only during uninstall and to do 
>> that I am using sql:SqlDatabase element. The problem is that the 
>> database is dropped during a major upgrade. How can I prevent it from
happening?
>>
>> Here is the command I am using:
>> <Component Id="KmfDatabase"
>> Guid="{82B345FC-A889-44c2-A964-DE2495DC0D29}">
>>                 <sql:SqlDatabase Id="TaitKmf"  Database="TaitKmf"
>> ContinueOnError="yes" CreateOnReinstall="no" CreateOnUninstall="no"
>>                                   CreateOnInstall="no"
>> DropOnReinstall="no" DropOnUninstall="yes" DropOnInstall="no"
>> Server="[ComputerName]"/>
>>             </Component>
>>
>> =====================================================================
>> == This email, including any attachments, is only for the intended 
>> addressee.  It is subject to copyright, is confidential and may be 
>> the subject of legal or other privilege, none of which is waived or 
>> lost by reason of this transmission.
>> If the receiver is not the intended addressee, please accept our 
>> apologies, notify us by return, delete all copies and perform no 
>> other act on the email.
>> Unfortunately, we cannot warrant that the email has not been  altered

>> or corrupted during transmission.
>> =====================================================================
>> ==
>>
>>
>> ---------------------------------------------------------------------
>> --------- Open Source Business Conference (OSBC), March 24-25, 2009, 
>> San Francisco, CA -OSBC tackles the biggest issue in open source: 
>> Open Sourcing the Enterprise -Strategies to boost innovation and cut 
>> costs with open source participation -Receive a $600 discount off the

>> registration fee with the source code: SFAD 
>> http://p.sf.net/sfu/XcvMzF8H 
>> _______________________________________________
>> WiX-users mailing list
>> WiX-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wix-users
>>
>>  
>>     
>
> ======================================================================
> = This email, including any attachments, is only for the intended 
> addressee.  It is subject to copyright, is confidential and may be the

> subject of legal or other privilege, none of which is waived or lost 
> by reason of this transmission.
> If the receiver is not the intended addressee, please accept our 
> apologies, notify us by return, delete all copies and perform no other

> act on the email.
> Unfortunately, we cannot warrant that the email has not been  altered 
> or corrupted during transmission.
> ======================================================================
> =
>
>
>
>   
> ----------------------------------------------------------------------
> --
>
> ----------------------------------------------------------------------
> -------- Open Source Business Conference (OSBC), March 24-25, 2009, 
> San Francisco, CA -OSBC tackles the biggest issue in open source: Open

> Sourcing the Enterprise -Strategies to boost innovation and cut costs 
> with open source participation -Receive a $600 discount off the 
> registration fee with the source code: SFAD 
> http://p.sf.net/sfu/XcvMzF8H
> ----------------------------------------------------------------------
> --
>
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users
>   

=======================================================================
This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be the
subject of legal or other privilege, none of which is waived or lost by
reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no other
act on the email.
Unfortunately, we cannot warrant that the email has not been  altered or
corrupted during transmission.
=======================================================================


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to