Tạo file cài đặt với WIX tool set kèm ghi dữ liệu SQL

Mình tạo bộ công cụ bổ trợ cho phần mềm Advance steel (AS), gồm các file .DLL, hình ảnh. Để cài đặt bộ công cụ này, cần copy các file này vào 02 thư mục cài đặt của phần mềm AS (người dùng chọn từ cửa sổ), ghi dữ liệu vào cơ sở dữ liệu của AS bằng SQL, ngoài ra cần ghi dữ liệu vào file XML. Mình có tạo project, mã như sau, nhưng khi chạy cài đặt báo lỗi: "Failed to connect to SQL database (-2147467259 ASTORRULES)

<?xml version="1.0" encoding="UTF-8"?>
<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">
	<?define MyWpfApplication_TargetDir=$(var.MyWpfApplication.TargetDir)?>
	<?define Win64 = "yes" ?>
	<?define SqlInstanceName = "YourInstanceNameHere" ?>
	<?define WixExtension ="WixSqlExtension" ?>
  <Product Id="17a4f85a-1219-4143-a0d6-e9ebc6084064" Name="My Wpf Application" Language="1033" Version="1.0.0.0" Manufacturer="Mesta-Automation.com" UpgradeCode="3936e1bc-c06c-45ae-b1db-430cf31dd48b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
	
    <Icon Id="icon.ico" SourceFile="$(var.ProjectDir)Icon.ico" />
    <Property Id="ARPPRODUCTICON" Value="icon.ico" />

    <WixVariable Id="WixUIBannerBmp" Value="Images\installer_top-banner.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="Images\installer_background.bmp" />
    <WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)\license.rtf" />

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    <UIRef Id="WixUI_InstallDir" />


    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Feature Id="ProductFeature" Title="My Wpf Application" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
	  <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
	    
		<!--
		 <ComponentGroupRef Id="Files_files" /> -->
    </Feature>

	  <Binary Id="CreateUpsizingDatabase" SourceFile="FILECAIDAT\dbo.RULE_HRLDefinition.sql" />
	  <util:User Id="SQLUser" Name="ADMINISTRATOR\CANHQUY" />
	  <sql:SqlDatabase Id="SqlDatabase" Database="ASTORRULES" Server="(LocalDB)\AdvanceSteel2022" User="SQLUser" />

  </Product>

	
	
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MyWpfApplication">
          <Directory Id="Files" Name="Files" />
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyWpfApplication" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>
  </Fragment>
	<Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="9bd13330-6540-406f-a3a8-d7f7c69ae7f9">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="MyWpfApplication" Description="MyWpfApplication" Target="[INSTALLFOLDER]MyWpfApplication.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\MyWpfApplication" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="cde1e030-eb64-49a5-b7b8-400b379c2d1a">
        <Shortcut Id="ApplicationDesktopShortcut" Name="MyWpfApplication" Description="MyWpfApplication" Target="[INSTALLFOLDER]MyWpfApplication.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\MyWpfApplication" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
  </Fragment>
 
  
  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
      <!-- <Component Id="ProductComponent"> -->
      <!-- TODO: Insert files, registry keys, and other resources here. -->
      <!-- </Component> -->
      <Component Id="file_ASNetJoints.dll" Guid="0f9a1acd-803f-4ecb-a283-7537a05a5eb1">
        <File Id="file_ASNetJoints.dll" Name="ASNetJoints.dll" Source="FILECAIDAT\ASNetJoints.dll" />
      </Component>
		<Component Id="SqlComponent" Guid="15CCE46E-8EA5-42CA-80C5-AC3DB30A9716">
			<sql:SqlScript Id="CreateDatabases" SqlDb="SqlDatabase" ExecuteOnInstall="yes" BinaryKey="CreateUpsizingDatabase" />
			<CreateFolder/>
		</Component>
    </ComponentGroup>
	
  </Fragment>

	<Fragment>
		<!-- Định nghĩa Binary cho file SQL -->
		<Binary Id="SqlScriptBinary" SourceFile="FILECAIDAT\dbo.RULE_HRLDefinition.sql" />


		<CustomAction Id="ChangeSqlScript"
          BinaryKey="Installer.CA"
          DllEntry="ChangeSqlScript"
          Execute="immediate"
          Return="check"
          Impersonate='yes'/>
		<InstallExecuteSequence>
			<Custom Action="ChangeSqlScript" After="InstallFinalize">NOT Installed AND VersionNT</Custom>
		</InstallExecuteSequence>
	</Fragment>

</Wix>

212121

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?