【问题标题】:Use WIX to create a database with a script instead of a SQLDatabase element使用 WIX 使用脚本而不是 SQLDatabase 元素创建数据库
【发布时间】:2013-07-25 23:29:14
【问题描述】:

我想在安装过程中使用 WIX 创建数据库。我知道我可以使用这样的 SqlDatabase 元素来做到这一点:

<sql:SqlDatabase Id='SqlDatabase' Database='MyDB'  Server='localhost'  Instance='MyInst'
                  CreateOnInstall='yes' DropOnUninstall='yes' ContinueOnError='yes'>
                <sql:SqlScript Id='CreateTables' BinaryKey='CreateTables' ExecuteOnInstall='yes'/>
              </sql:SqlDatabase>

问题是我想在脚本文件中创建数据库,而不是在 SqlDatabase 元素中。有没有办法做到这一点?

如果我将 CreateOnInstall 设置为“否”,脚本将不会运行。

【问题讨论】:

    标签: wix


    【解决方案1】:

    是的,使用 SqlDatabase 元素连接到主数据库(或您知道存在的任何其他数据库),然后 SqlScript 可以完成您想要的所有工作。您可能需要更新您的 SqlScript,使其以正确的数据库为目标。

    <sql:SqlDatabase Id='SqlDatabase' Database='master'  Server='localhost'  Instance='MyInst'>
       <sql:SqlScript Id='CreateTables' BinaryKey='CreateTables' ExecuteOnInstall='yes' />
    </sql:SqlDatabase>
    

    【讨论】:

    • 使用您的 sn-p,您将无法编译 MSI 包,您将收到以下错误: sql:SqlDatabase 元素必须指定以下属性之一:CreateOnInstall, CreateOnUninstall、DropOnInstall 或 DropOnUninstall。
    • 您的代码不起作用,在我的情况下(VS 2019,WiX 扩展)它会产生 Dan 已经描述的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    相关资源
    最近更新 更多