我正在尝试使用WiX恢复备份数据库文件,并且已创建数据库但未恢复任何表和数据。好像它只是创建数据库而不做任何其他事情。不确定这是否与WiX有关或与MSSQL使用有关。这是WiX XML:
<Component Id="sql_backup_restore" Guid="8C95F258-7AB7-4A3A-A0CD-438FC61D45CC">
<CreateFolder Directory="javaaaanew_dir"/>
<sql:SqlDatabase Id="aaanew3_db" Server="[MSSQLSERVER]" Database="master" ConfirmOverwrite="yes" ContinueOnError="yes" DropOnReinstall="no" DropOnInstall="no" DropOnUninstall="no" CreateOnInstall="yes" CreateOnReinstall="no" CreateOnUninstall="no">
<!-- restore blankaaa database -->
<sql:SqlString Id="attach_db" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="1" SQL="RESTORE DATABASE blankaaa FROM DISK = '[blankaaaBAK]' WITH RECOVERY;" />
<!-- rename blankaaa to aaanew3 -->
<sql:SqlString Id="alter_db_name" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="2" SQL="USE master;GO;ALTER DATABASE blankaaa Modify Name = 'aaanew3' GO;" /> <!-- should fail here if preexisting database? -->
<!-- change aaanew3 dbowner to 'sa' -->
<sql:SqlString Id="alter_db_owner" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="3" SQL="ALTER AUTHORIZATION ON DATABASE::aaanew3 TO sa;" />
<!-- add user 'sa' to database security? -->
<sql:SqlString Id="alter_db_sa" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="4" SQL="USE [aaanew3];GO;CREATE USER [sa] FOR LOGIN [sa];GO;" />
<!-- add user mapping for 'sa' on aaanew3 with schema 'dbo' -->
<sql:SqlString Id="alter_db_schema" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="5" SQL="USE [aaanew3];GO;ALTER USER [sa] WITH DEFAULT_SCHEMA=[dbo];GO;" />
</sql:SqlDatabase>
</Component>
我也试过了#34; WITH RECOVERY&#34;并在方括号周围使用转义序列:
<sql:SqlString Id="attach_db" ExecuteOnInstall ="yes" ExecuteOnReinstall="no" ExecuteOnUninstall="no" ContinueOnError="yes" Sequence="1" SQL="RESTORE DATABASE blankaaa FROM DISK = '[\[]blankaaaBAK[\]]' WITH RECOVERY;" />
在文档中似乎不太清楚这种做法的正确方法。
答案 0 :(得分:6)
而不是尝试引用数据库文件的wix名称,我使用了以下内容:
SQL="RESTORE DATABASE blankaaa FROM DISK = '[INSTALLFOLDER]javaaaanew\blankaaa.bak' WITH RECOVERY"