使用< sql:SqlScript>通过Wix运行SQL脚本文件元件 [英] Running SQL Script file through Wix using <sql:SqlScript> element

查看:252
本文介绍了使用< sql:SqlScript>通过Wix运行SQL脚本文件元件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我没有得到一个新的Wix安装程序。我有一个要求,我必须提供凭据的SQL Server登录和从一个特定的路径运行脚本。发生错误。项目已成功创建.msi已创建。运行后,我收到以下错误:



错误26204.错误-2147217900:failed to执行SQL字符串,错误详细信息:'»'附近的语法不正确。SQL键:CreateUpsizingDatabase SQL字符串:print convert(varchar(25),GetDate(),121)+'执行文件:SqlTest.sql' strong>



我的Sql脚本文件如下:



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



以下是我的代码

 <?xml version =1.0encoding =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 =SqlTestLanguage =1033Version =1.0.0.0Manufacturer =BLRSCCMCAS01UpgradeCode =0931a445-07bf-4494-b130-a1f96155021f
< Package InstallerVersion =200Compressed =yesInstallScope =perMachine/>

< MajorUpgrade DowngradeErrorMessage =已安装了[ProductName]的较新版本。 />
< MediaTemplate />

< Feature Id =ProductFeatureTitle =SqlTestLevel =1>
< ComponentGroupRef Id =ProductComponents/>
< / Feature>

< Binary Id =CreateUpsizingDatabaseSourceFile =C:\ Temp\SqlTest.sql/>

< util:User Id =SQLUserName =[User]Password =[Password]/>

< sql:SqlDatabase Id =SqlDatabaseDatabase =[MyDb]Server =[Server]User =SQLUser/&

< / Product>

< Fragment>
< Directory Id =TARGETDIRName =SourceDir>
< Directory Id =ProgramFilesFolder>
< Directory Id =INSTALLFOLDERName =SqlTest/>
< / Directory>
< / Directory>
< / Fragment>

< Fragment>
< ComponentGroup Id =ProductComponentsDirectory =INSTALLFOLDER>
< Component Id =SqlComponentGuid =15CCE46E-8EA5-42CA-80C5-AC3DB30A9716>
< sql:SqlScript Id =CreateDatabasesSqlDb =SqlDatabaseExecuteOnInstall =yesBinaryKey =CreateUpsizingDatabase/>
< CreateFolder />
< / Component>
< / ComponentGroup>
< / Fragment>

< / Wix>


解决方案

看起来您有 UTF8 BOM ()。尝试使用Visual Studio中的高级保存选项将文件保存为Unicode(UTF8无签名)。


am new to Wix Installer.I have a requirement where I have to provide credentials for SQL Server login and run a script from a specific path.

Am not getting what's going wrong.The project is build successfully and .msi is created.After running it I get following Error:

Error 26204. Error -2147217900: failed to execute SQL string, error detail: Incorrect syntax near '»'., SQL key: CreateUpsizingDatabase SQL string: print convert(varchar(25),GetDate(),121) + ' Executing file: SqlTest.sql'

My Sql Script File is as below:

print convert(varchar(25),GetDate(),121) + ' Executing file: SqlTest.sql'

Below is My code:

<?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>

解决方案

It looks like you have a UTF8 BOM () in there. Try saving the file as "Unicode (UTF8 Without signature)" using the advanced save options in visual studio.

这篇关于使用&lt; sql:SqlScript&gt;通过Wix运行SQL脚本文件元件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆