无法使用Wix安装数据库

时间:2016-05-24 04:10:02

标签: wix

我已经尝试过很多次但是在sql server中没有创建mgmt studio db sa用户已经创建我已更改用户名但不起作用 请参考以下文件:

Product.wxs:`

<?xml version="1.0" encoding="UTF-8"?>
<!--For [DBStep:1] Sql Database Add Reffrence 1] xmlns:util 2]xmlns:sql-->
<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="680B2B06-567E-4BDB-9C37-63830049B51F"
           Name="MyApp" Language="1033" Version="1.0.0.0" Manufacturer="My System Pvt Ltd"
           UpgradeCode="A25F60C4-4037-4DA8-BA2F-6C482EF7D05A">

    <Package Id="*" InstallerVersion="100" Compressed="yes" InstallScope="perMachine"
              InstallPrivileges="elevated" ReadOnly="yes"/>

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <!--Add Cab1.cab File inside the Package-->
    <Media Id="1" Cabinet="cab1.cab" EmbedCab="yes" />

    <!--For [DBStep:2] Create User and add *.sql File-->
    <util:User Id="SQLUser" Name="[SQLUSER]" Password="[SQLPASSWORD]" />
    <!--Create Database User-->
    <Binary Id="CreateTable" SourceFile="CreateTable.sql" />
    <!--Add your script File-->
    <Property Id="SQLUSER">sa</Property>
    <Property Id="SQLPASSWORD">amit@123</Property>
    <Property Id="SQLSERVER">LOCAL</Property>

    <!--Here We Install Our Main App-->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MY System Pvt Ltd"/>
      </Directory>

      <!-- Step 1: For the Program Menu -->
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="My System Pvt Ltd"/>
      </Directory>

      <!--Step 2:For Desktop Folder-->
      <Directory Id="DesktopFolder"/>

      <!--Step 3:For StartUp Folder-->
      <Directory Id="StartupFolder"/>

    </Directory>

    <!--Step 4 :Add Main App exe-->
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Id="myapplication.exe" Guid="854D88DA-D213-4805-B3DC-51F43837B124">
        <File Source="$(var.WixDemoWPFAppVS2012.UI.TargetPath)" Name="MYApp.exe"
              Id="MyAppEXE" KeyPath="yes"/>
      </Component>
      <!--[DBStep:3]Componant for Database-->
      <Component Id="SqlComponent" Guid="1B3F5D84-D1A0-409D-9ADC-71C562344FEE" KeyPath="yes">
        <sql:SqlDatabase Id="SqlDatabase" Database="Foobar" User="SQLUser"  Instance="SQLEXPRESS"
                         Server="[SQLSERVER]" CreateOnInstall="yes" DropOnUninstall="yes"
                          ContinueOnError="yes" >


          <sql:SqlScript Id="CreateTable" BinaryKey="CreateTable" ExecuteOnInstall="yes" />
        </sql:SqlDatabase>
      </Component>
    </DirectoryRef>

    <!-- Step 1.1: Add the shortcut to your installer package Program Menu or Start Menu-->
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="8C4AC870-043C-4D36-A868-35354F2A0D9A">
        <!--Add Shortcut of the Application in start Menu-->
        <Shortcut Id="ApplicationStartMenuShortcut" Name="MyApp" Description="My Application Description"
            Target="[INSTALLFOLDER]MyApp.exe" WorkingDirectory="INSTALLFOLDER">
          <!--Add Icon to the ShortCut-->
          <Icon Id="MYPMenuIcon"  SourceFile=".\Desktop.ico" />
        </Shortcut>
        <Shortcut Id="UninstallShortcut"
                  Name="Uninstall My Software"
                  Description="Uninstalls My Software data"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]" />
        <!--Remove the Folder At time of Uninstall-->
        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue Root="HKCU"  Key='Software\[Manufacturer]\[ProductName]'
                       Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>

    </DirectoryRef>

    <!-- Step 2.1: Add the shortcut to your installer package For DeskTop-->
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationDeskShortcutComp" Guid="29B9A804-9B2B-4E57-8803-E13C702FE100">
        <Shortcut Id="ApplicationDeskShortcut" Name="MYAppDesk"
                  Description="My Application Description" Target="[INSTALLFOLDER]MyApp.exe"
                  WorkingDirectory="INSTALLFOLDER">
          <Icon Id="MYDeskIcon"  SourceFile=".\Desktop.ico" />
        </Shortcut>
        <RemoveFolder Id="DesktopFolder" On="uninstall"/>
        <RegistryValue Root="HKCU"  Key='Software\[Manufacturer]\[ProductName]'
                       Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <!--Step 3.1: add Shortcut to StartUp Folder to run application when you login-->
    <DirectoryRef Id="StartupFolder">
      <Component Id="ApplicationStartUpShortcutComp" Guid="C4340A05-0D11-4F54-9DD7-7A058A35DE43">
        <Shortcut Id="ApplicationStartUpDeskShortcut" Name="MYAppDesk" Description="My Application Description"
            Target="[INSTALLFOLDER]MyApp.exe" WorkingDirectory="INSTALLFOLDER">
          <Icon Id="MyIconStartUp"  SourceFile=".\Desktop.ico" />
        </Shortcut>
        <RemoveFolder Id="StartupFolder" On="uninstall"/>
        <RegistryValue Root="HKCU"  Key='Software\[Manufacturer]\[ProductName]'
                       Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <!--Add Component-->
    <Feature Id="MainApplication" Title="Main Application" Level="1">
      <ComponentRef Id="myapplication.exe" />
      <!--Step 1.2:Add Start menu or program  Shortcut-->
      <ComponentRef Id="ApplicationShortcut" />
      <!--step 2.2Add DeskTop Shortcut-->
      <ComponentRef Id="ApplicationDeskShortcutComp" />
      <!--step 3.2Add DeskTop Shortcut-->
      <ComponentRef Id="ApplicationStartUpShortcutComp"/>
      <!--[DBStep:4]Add Database Componant to the WXS file-->
      <ComponentRef Id="SqlComponent" />
    </Feature>
  </Product>
</Wix>

`

CreateTable.sql:`

CREATE TABLE Test (Value1 CHAR(50), Value2 INTEGER)
CREATE INDEX TestIndex ON Test (Value1)

`

0 个答案:

没有答案