Skip to content

Instantly share code, notes, and snippets.

@rrreese
Created November 18, 2012 09:25
Show Gist options
  • Save rrreese/4104368 to your computer and use it in GitHub Desktop.
Save rrreese/4104368 to your computer and use it in GitHub Desktop.
Using WiX to install SQL databases and execute SQL scripts
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="5fffca1a-e20b-4b76-924a-a915f3124a11" Name="WixTest" Language="1033" Version="1.0.0.0" Manufacturer="WixTest" UpgradeCode="8e607b01-0d14-4c3e-b135-53631a6b44ff">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<!-- Define Installation Components-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="StartMenuFolder"/>
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="WixTest">
<Component Id="ProductComponent" Guid="b3915d8f-0301-40a0-8d09-66076e0ac43e">
<File Id="testFile" Name="testFile.txt" Source="c:\TestFile.txt">
<Shortcut Id="testShortcut" Name="testFileShortCut" Directory="StartMenuFolder" Advertise="yes" />
</File>
<File Id="testFile1" Name="testFile1.txt" Source="c:\TestFile1.txt" />
<File Id="testFile2" Name="testFile2.txt" Source="c:\TestFile2.txt" />
<File Id="testFile3" Name="testFile3.txt" Source="c:\TestFile3.txt" />
</Component>
</Directory>
</Directory>
</Directory>
<!--Install-->
<Feature Id="ProductFeature" Title="WixTest" Level="1">
<ComponentRef Id="ProductComponent" />
</Feature>
</Product>
</Wix>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension">
<util:User Id="SQLUser" Name="[SQLUSER]" Password="[SQLPASSWORD]" />
<sql:SqlDatabase Id="SqlDatabase"
Database="TestDatabase"
Server="[SQLSERVER]"
Instance="[SQLINSTANCE]"
CreateOnInstall="yes"
DropOnUninstall="yes"
User="SQLUser">
<sql:SqlScript Id="TestScript" ExecuteOnInstall="yes" BinaryKey="CreateTablesBin"></sql:SqlScript>
</sql:SqlDatabase>
<Binary Id="testBinary" SourceFile="E:\DOCUMENTS\Code\WixTest\test.sql" />
CREATE TABLE [Test] ([ID] [int] NOT NULL)
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
xmlns:sql="http://schemas.microsoft.com/wix/SqlExtension">
<Product Id="5FFFCA1A-E20B-4B76-924A-A915F3124A11"
Name="WixTest"
Language="1033"
Version="1.0.0.0"
Manufacturer="WixTest"
UpgradeCode="8E607B01-0D14-4C3E-B135-53631A6B44FF">
<Package InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<!-- Define Instalation Components-->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="StartMenuFolder"/>
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="WixTest">
<Component Id="ProductComponent" Guid="B3915D8F-0301-40A0-8D09-66076E0AC43E">
<File Id="testFile" Name="testFile.txt" Source="c:\TestFile.txt">
<Shortcut Id="testShortcut" Name="testFileShortCut"
Directory="StartMenuFolder" Advertise="yes" />
</File>
<File Id="testFile1" Name="testFile1.txt" Source="c:\TestFile1.txt" KeyPath="yes"/>
<File Id="testFile2" Name="testFile2.txt" Source="c:\TestFile2.txt" />
<File Id="testFile3" Name="testFile3.txt" Source="c:\TestFile3.txt" />
<util:User Id="SQLUser" Name="[SQLUSER]" Password="[SQLPASSWORD]" />
<sql:SqlDatabase Id="SqlDatabase"
Database="TestDatabase"
Server="[SQLSERVER]"
Instance="[SQLINSTANCE]"
CreateOnInstall="yes"
DropOnUninstall="yes"
User="SQLUser">
<sql:SqlScript Id="TestScript" ExecuteOnInstall="yes" BinaryKey="testBinary" />
</sql:SqlDatabase>
</Component>
</Directory>
</Directory>
</Directory>
<!--Install-->
<Feature Id="ProductFeature" Title="WixTest" Level="1">
<ComponentRef Id="ProductComponent" />
</Feature>
<Binary Id="testBinary" SourceFile="E:\DOCUMENTS\Code\WixTest\test.sql" />
</Product>
</Wix>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment