Wix,创建数据库并运行迁移

问题描述 投票:0回答:1

我们使用Fluent Migrator在我们的WPF应用程序中迁移SQL Server数据库。现在我使用Wix Toolset制作安装程序,并尝试将迁移添加为安装的一部分。

我有一个自定义操作执行迁移和一个带有SqlDatabase标记的组件,用于创建数据库。如果我在安装期间指向现有数据库并且如果选择不存在的数据库,则数据库创建工作正常,则迁移工作正常。但是将它们一起运行我得到一个SQL Server错误。

*Cannot open database "Database" requested by the login. The login failed.
Login failed for user 'User'.!*

创建MigrationRunner时发生错误:

new MigrationRunner(migrationsAssembly, migrationContext, processor);

SqlDatabase如下所示:

<sql:SqlDatabase Id='SqlDatabase.IntegratedAuthentication' 
    Database='[DATABASE_NAME]' 
    Server='[DATABASE_SERVER]' 
    CreateOnInstall='yes' 
    DropOnUninstall='no' 
    ContinueOnError='no' />

在我的日志中,我可以看到CreateDatabase操作在迁移开始之前完成,是否有人知道为什么会发生这种情况或如何绕过它?

wpf wix fluent-migrator
1个回答
0
投票

您的示例似乎缺少sql:SqlScript元素的BinaryKey属性?

这是我写的一个工作脚本的摘录。

首先,定义要运行的脚本。 (即BinaryKey属性的值)

<Binary Id="CreateTablesBin" SourceFile="Database\[CreateScript]"></Binary>
<Binary Id="FillTablesBin" SourceFile="Database\[DataScript]"></Binary>
<Binary Id="DropTablesBin" SourceFile="Database\[RollbackScript]"></Binary>

然后定义一个功能来运行数据库脚本。

<Feature Id="ProductFeature" Title="DB Server Setup" Level="1">
  <ComponentGroupRef Id="MyWebComponents"/>
  <ComponentGroupRef Id="IISConfiguration"/>
  <Component Id="IntegratedSecurity" Guid="[GUID Here]" Directory="INSTALLFOLDER">
    <sql:SqlDatabase Id="MySqlDatabase" Database="[DATABASE_NAME]" Server="[DATABASE_SERVER]" CreateOnInstall="yes" DropOnUninstall="yes" ContinueOnError="yes"> <!-- Don't specify user for Integrated Authentication / Win Authentication -->
      <sql:SqlScript Id="CreateTables" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="CreateTablesBin" ContinueOnError="no" />
      <sql:SqlScript Id="FillTables" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FillTablesBin"  ContinueOnError="no"/>
      <sql:SqlScript Id="DropTables" ExecuteOnInstall="no" ExecuteOnUninstall="yes" BinaryKey="DropTablesBin"  ContinueOnError="yes"/>
    </sql:SqlDatabase>
    <CreateFolder/>
  </Component>     
</Feature>

我不确定你是否需要2个ComponentGroupRef元素。我已经包含在这里以防万一它需要。

© www.soinside.com 2019 - 2024. All rights reserved.