Maryann,

While I haven't explicitly done this myself, the basic process should be
as follows:

1. Create the relevant UI components that execute during the uninstall
UI sequence. You will need a control that sets a property (say
"UNINSTALLDB"). [Sounds like you've already done this part]

2. Add an "SqlString" element to your component that corresponds to your
DB that removes the database conditionally in T-SQL during the uninstall
sequence, something like the following (you may have to adjust the
condition test in the T-SQL to suit your property):

(note that this also uses an MSI property "DatabaseName" to determine
which database to drop, and you will need to define a "MasterDB" in your
WiX sources too -- see below)

<sql:SqlString Id="RemoveDBDuringUninstall" ExecuteOnUninstall="yes"
Sequence="??" SqlDb="MasterDB" SQL="
IF ('[UNINSTALLDB]' = '1') AND EXISTS (SELECT [\[]name[\]] FROM
[\[]sys[\]].[\[]databases[\]] WHERE [\[]name[\]] = '[DatabaseName]')
BEGIN
  ALTER DATABASE [\[][DatabaseName][\]] SET SINGLE_USER WITH ROLLBACK
IMMEDIDATE
  DROP DATABASE [\[][DatabaseName][\]]
END 
" />


<sql:SqlDatabase Id="MasterDB" Server="[DatabaseServerName]"
Instance="[DatabaseInstanceName]" Database="master" />
(this uses properties for the server name and instance names, which you
would also need to set)


You may also have to consider what happens if something fails during the
uninstall after this action has been performed. Thus you might want to
backup the DB first, and restore the DB during a rollback sequence (for
uninstall).  However, this type of error handling during an uninstall is
probably a lot less important that during an upgrade or an install.


Hope this helps a bit...(and my apologies if this doesn't quite work as
written as I have not explicitly tested the above)

Robert


Robert Turner
Director of Development
rtur...@objectworld.com

Objectworld, The IT Telephony Company TM
308 Legget Drive, Ottawa, Ontario K2K 1Y6
Phone: +1 (613) 599-9698, x. 233 | Fax: +1 (613) 599-7457
http://www.objectworld.com

Objectworld is a Microsoft Gold Certified Partner

-----Original Message-----
Date: Fri, 12 Jun 2009 14:05:27 +0530
From: Maryann Fernandes <itsmary...@gmail.com>
Subject: [WiX-users]  Drop SQL Server database during uninstall
To: wix-users@lists.sourceforge.net
Message-ID:
        <77b603ef0906120135i7978ae6bhdacd83588238c...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I want to do a similar thing. I want to provide an option for deleting
database during uninstallation. I added a checkbox to prompt the user,
and
bound the checkbox to a property, but I don't know how to drop the
database
if the property is true.
The "droponuninstall" attribute on SqlDatabase does not take a property
as
its value.

I thought of using a sql script to drop the database. But there is no
<condition> child allowed for <SqlScript>. Even the inner text does not
tkae
a condition.

Please help.

Regards,
Maryann

Romeo S. wrote:
>
> Hi,
>
> Our package creates a database during installation and we only want to
> drop the database during uninstall when the PROPERTIES DROPDB="1".
>
> What i did was i've created a component:
> <Component Id="createDB" Guid="8D0757C0-B204-4A99-8FA1-4F3235FA2CAF">
>       <CreateFolder Directory="INSTALLDIR" />
>       <sql:SqlDatabase Id="createSqlDB" CreateOnInstall="yes"
> Server="[SQLSERVER_SERVER]" Database="[SQLSERVER_DATABASE]">
>               <sql:SqlScript Id="createScript" ExecuteOnInstall="yes"
> ContinueOnError="no" BinaryKey="create_DB.sql"/>
>       </sql:SqlDatabase>
> </Component>
>
> And then i created another database for dropping the database:
> <Component Id="dropDB" Guid="D32A0748-A505-45B4-B419-BF21C71FF0B6">
>       <CreateFolder Directory="INSTALLDIR" />
>       <sql:SqlDatabase Id="dropSqlDB" DropOnUninstall="yes"
> Server="[SQLSERVER_SERVER]" Database="[SQLSERVER_DATABASE]" />
>       <Condition><![CDATA[DROPDB="1"]]></Condition>
> </Component>
>
> What is the right way to do this? All we want is drop the database on
> uninstall only if DROPDB="1". Thank you in advance.
>
> Regards,
> Romeo


-----------------------------------------------

This transmission (including any attachments) may contain confidential 
information, privileged material (including material protected by the 
solicitor-client or other applicable privileges), or constitute non-public 
information. Any use of this information by anyone other than the intended 
recipient is prohibited. If you have received this transmission in error, 
please immediately reply to the sender and delete this information from your 
system. Use, dissemination, distribution, or reproduction of this transmission 
by unintended recipients is not authorized and may be unlawful. 

Any views, opinions and content presented in this e-mail are solely those of 
the author and may not represent those of Objectworld Communications Corp. 

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to