How to restore a database from a .bak file (backing up the database) in the wix 3.9 installer

I am trying to restore a sql server database from a .bak file (database backup file) using the wix 3.9 installer. But, unfortunately, this does not happen. Here are my trial codes

<Fragment> <Binary Id="PHRBackupBin" SourceFile="Database/PHR.bak"></Binary> <!--<util:User Id="SQLUserSA" Name="[DB_USER]" Password="[DB_PASSWORD]"></util:User>--> <util:User Id="SQLUserSA" Name="sa" Password="sa"></util:User> <DirectoryRef Id="INSTALLFOLDER"> <Component Id="SqlComponent" Guid="8A1C82DB-1DD3-4FB5-8600-4F370FE1E04B"> <Condition>NOT Installed</Condition> <sql:SqlDatabase Id="SqlServerDatabase" Database="PHR" Server="." CreateOnInstall="yes" DropOnUninstall="yes" User="SQLUserSA" ContinueOnError="no" Instance="SQLEXPRESS"> <sql:SqlScript Id="PHRBackup" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="PHRBackupBin" ContinueOnError="no" /> </sql:SqlDatabase> <CreateFolder/> </Component> </DirectoryRef> <ComponentGroup Id="DatabaseConfiguration"> <ComponentRef Id="SqlComponent"></ComponentRef> </ComponentGroup> 

The above installer starts up successfully if I replace the .sql file (sql script) . I also tried writing a script file to restore the database, but no luck. May I ask the community how to run the .bak file from the wix installer.

Thanks in advance

+5
source share
1 answer

Unfortunately, you cannot restore it using the bak file. This is not a script (which is required for the sql: SqlScript component), it is a backup file that is different.

A .bak file is usually a native backup file created in SQL Server.

The .sql file is a script and may even be a dump of mySQL, which at startup will look like recovery, although technically it will create a new db.

This is confirmed in the wix documentation: http://wixtoolset.org/documentation/manual/v3/xsd/sql/sqlscript.html

0
source

Source: https://habr.com/ru/post/1210659/


All Articles