如何使用Wix运行SQL脚本以创建数据库 [英] How to run sql script to create database using Wix

查看:103
本文介绍了如何使用Wix运行SQL脚本以创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用Wix创建数据库时遇到问题。我可以找到的示例(请参见下面的链接)都是首先使用wix创建数据库并运行create table sql脚本。问题是我需要将wix设置为使用CREATE DATABASE运行sql脚本来创建数据库和表,而不是首先使用.wxs文件中的SqlDatabase标记来创建数据库。在Wix中可以这样做吗?我正在使用SQL Server Express。有关如何执行此操作的任何示例都将有所帮助。

I'm running into problem creating database with Wix. The examples(see link below) i can find are all creating database first using wix and running a create table sql script. The problem is that i need to set the wix to run sql script with CREATE DATABASE to create the database and tables, and NOT to create the database first using the SqlDatabase tag in .wxs file. Is this possible to do this in Wix? I'm using SQL Server Express. Any example on how to do this would be helpful.

http://www.rrreese.com/Article/Show/WiX%20SQL

sql脚本示例:

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

请先谢谢。

推荐答案

为什么没有一个包含SQL代码来创建数据库的脚本文件。

Why don't you have a script file containing SQL code to create the database.

<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 Name='SQL app 1.0' Id='DB501C18-86C7-4D14-AEC0-86416A69ABDE' Language='1033' Codepage='1252'
     Version='1.0.0' Manufacturer='ABC Ltd.'>
            <Package Id='????????-????-????-????-????????????' Keywords='Installer' Description="SQL App 1.0 Installer"
              Comments='Comment.' Manufacturer='ABC Ltd.' InstallerVersion='100'
              Languages='1033' Compressed='yes' SummaryCodepage='1252' />
        <Media Id='1' Cabinet='Sample.cab' EmbedCab='yes' />
        <User Id="MySQLUser" Name="[SQLUSER]" Password="[SQLUSERPASSWORD]"></User>
        <Directory Id='TARGETDIR' Name='SourceDir'>
            <Directory Id='ProgramFilesFolder' Name='PFiles'>
                <Directory Id='INSTALLDIR' Name='TestSQL'>
                      <Component Id="MySqlComponent" Guid="C50999A0-02FD-42d5-9F65-7375318DD328">
                        <SqlDatabase Id="MySqlDatabase" Database="MyDatabase" Server="[SQLSERVER]" Instance="[SQLINSTANCE]"
                            CreateOnInstall="yes" DropOnUninstall="yes" User="MySQLUser" ContinueOnError="yes">
                              <SqlScript Id="CreateDatabase" ExecuteOnInstall="yes" BinaryKey="CreateTablesBin"></SqlScript>
                        </SqlDatabase>
                      </Component>
                </Directory>
             </Directory>
         </Directory>
        <Binary Id="CreateTablesBin" src="CreateDatabase.sql"></Binary>
        <Feature Id='Complete' Level='1' Description="Full" Title="Full Installation">
            <ComponentRef Id='MySqlComponent' />
        </Feature>
    </Product>
</Wix>

这篇关于如何使用Wix运行SQL脚本以创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆