使用<sql:sqlscript> element </sql:sqlscript>通过Wix运行SQL Script文件

时间:2015-02-06 03:17:39

标签: sql-server database wix installer

我是Wix Installer的新手。我有一个要求,我必须提供SQL Server登录凭据并从特定路径运行脚本。

我没有遇到问题。项目已成功构建并且已创建.msi。运行后我得到以下错误:

错误26204.错误-2147217900:无法执行SQL字符串,错误详细信息:'»'附近语法错误。,SQL密钥:CreateUpsizingDatabase SQL字符串:print convert(varchar(25),GetDate( ),121)+'执行文件:SqlTest.sql'

我的Sql脚本文件如下:

print convert(varchar(25),GetDate(),121)+'执行文件:SqlTest.sql'

以下是我的代码:

<?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">
    <Product Id="*" Name="SqlTest" Language="1033" Version="1.0.0.0" Manufacturer="BLRSCCMCAS01" UpgradeCode="0931a445-07bf-4494-b130-a1f96155021f">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

        <Feature Id="ProductFeature" Title="SqlTest" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>

    <Binary Id="CreateUpsizingDatabase" SourceFile="C:\Temp\SqlTest.sql" />

    <util:User Id="SQLUser" Name="[User]" Password="[Password]" />

    <sql:SqlDatabase Id="SqlDatabase" Database="[MyDb]" Server="[Server]" User="SQLUser" />

    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="SqlTest" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="SqlComponent" Guid="15CCE46E-8EA5-42CA-80C5-AC3DB30A9716">
        <sql:SqlScript Id="CreateDatabases" SqlDb="SqlDatabase" ExecuteOnInstall="yes" BinaryKey="CreateUpsizingDatabase" /> 
        <CreateFolder/>
      </Component>
        </ComponentGroup>
    </Fragment>

</Wix>

2 个答案:

答案 0 :(得分:4)

看起来你有一个UTF8 BOM()。尝试使用visual studio中的高级保存选项将文件保存为“Unicode(UTF8无签名)”。

答案 1 :(得分:0)

我得到了同样的错误,UTF8有或没有签名都失败了。 我认为我们的脚本字符串中的字符会导致问题(在我的情况下,我包含了一些中文字符)。

我尝试从sql server重新生成sql脚本,并以 ANSI 格式保存此文件。有用! 我做了一些查询,中文字符在sql server中是正确的。

您可能想要引用的文章:http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Error-executing-sql-scripts-with-WIX-td1488703.html