Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用<;通过Wix运行SQL脚本文件;sql:SqlScript>;要素_Sql Server_Database_Wix_Installation - Fatal编程技术网

Sql server 使用<;通过Wix运行SQL脚本文件;sql:SqlScript>;要素

Sql server 使用<;通过Wix运行SQL脚本文件;sql:SqlScript>;要素,sql-server,database,wix,installation,Sql Server,Database,Wix,Installation,我是新的Wix安装程序。我需要提供SQL Server登录的凭据,并从特定路径运行脚本 我不知道出了什么问题。项目已成功生成,并且已创建.msi。运行它后,我得到以下错误: 错误26204。错误-2147217900:无法执行SQL字符串,错误详细信息:靠近“»”的语法不正确,SQL键:CreateUpsizingDatabase SQL字符串:ï»?打印转换(varchar(25),GetDate(),121)+“执行文件:SqlTest.SQL” 我的Sql脚本文件如下所示: 打印转换(va

我是新的Wix安装程序。我需要提供SQL Server登录的凭据,并从特定路径运行脚本

我不知道出了什么问题。项目已成功生成,并且已创建.msi。运行它后,我得到以下错误:

错误26204。错误-2147217900:无法执行SQL字符串,错误详细信息:靠近“»”的语法不正确,SQL键:CreateUpsizingDatabase SQL字符串:ï»?打印转换(varchar(25),GetDate(),121)+“执行文件:SqlTest.SQL”

我的Sql脚本文件如下所示:

打印转换(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>

看起来里面有一个(ï»?)。尝试使用visual studio中的高级保存选项将文件保存为“Unicode(UTF8不带签名)”。

我遇到了相同的错误,UTF8带签名或不带签名都失败。 我认为是脚本字符串中的字符导致了这个问题(在我的例子中,我包含了一些中文字符)

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


一篇你可能想参考的文章:

谢谢你,伙计……你为解决这个问题展示了一个很好的指导方向……上面的代码没有改变……如果sql脚本文件是在Visual studio中创建的,在我的例子中是VS12……它应该保存为选项编码,没有签名……如果sql文件中的文件是在SSMS中创建的,不需要做任何简单的事情拯救