将Azure bacpac文件导入本地db时出错,错误语法在EXTERNAL附近 [英] Error Importing Azure bacpac file to local db error incorrect syntax near EXTERNAL

查看:100
本文介绍了将Azure bacpac文件导入本地db时出错,错误语法在EXTERNAL附近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将db azure bacpac数据库文件导入本地sql server 2016时,出现以下错误.

When importing db fro azure bacpac file to local sql server 2016 I'm geting the following error.

Error SQL72014: .Net SqlClient Data Provider: Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'EXTERNAL'.
Error SQL72045: Script execution error.  The executed script: CREATE EXTERNAL DATA SOURCE [BoxDataSrc]
    WITH (
    TYPE = RDBMS,
    LOCATION = N'MYAZUREServer.database.windows.net',
    DATABASE_NAME = N'MyAzureDb',
    CREDENTIAL = [SQL_Credential]
    );

(Microsoft.SqlServer.Dac)

(Microsoft.SqlServer.Dac)

推荐答案

我今天也遇到了同样的问题.由于"WITH(TYPE = RDBMS)"仅适用于Azure SQL DB,因此当尝试将bacpac本地导入到SQL Server 2017时,会出现错误.感谢这篇文章,我确实找到了解决方案:

I ran into this same issue today. Since "WITH(TYPE = RDBMS)" is only applicable to Azure SQL DB, we get the error when attempting to import the bacpac into SQL Server 2017 on-premise. I did find a solution thanks to this article:

https://blogs.msdn .microsoft.com/azuresqldbsupport/2017/08/16/editing-a-bacpac-file/

相关步骤在此处重写:

  1. 制作bacpac文件的副本(以确保发生错误时的安全).
  2. 将文件扩展名更改为zip,然后将其解压缩到文件夹中.出人意料的是,bacpac实际上只是一个zip文件,而不是专有的且难以使用的文件.
  3. 找到model.xml文件并对其进行编辑以删除如下所示的部分:

  1. Make a copy of the bacpac file (for safety in case of errors).
  2. Change the file extension to zip, then decompress it into a folder. Surprisingly, a bacpac is actually just a zip file, not something proprietary and hard to get into.
  3. Find the model.xml file and edit it to remove the section that looks like this:

<Element Type="SqlExternalDataSource" Name="[BoxDataSrc]">
    <Property Name="DataSourceType" Value="1" />
    <Property Name="Location" Value="MYAZUREServer.database.windows.net" />
    <Property Name="DatabaseName" Value="MyAzureDb" />
    <Relationship Name="Credential">
        <Entry>
            <References Name="[SQL_Credential]" />
        </Entry>
    </Relationship>
</Element>

  • 如果您有多个这种类型的外部数据源,则可能需要为每个数据源重复步骤3.我只有一个.

  • If you have multiple external data sources of this type, you will pobably need to repeat step 3 for each one. I only had one.

    现在,您需要重新生成model.xml的校验和,以便bacpac不会认为它已被篡改(因为您刚刚对其进行了篡改).创建一个名为computeHash.ps1的PowerShell文件,并将此代码放入其中.

    Now you need to re-generate the checksum for model.xml so that the bacpac doesn't think it was tampered with (since you just tampered with it). Create a PowerShell file named computeHash.ps1 and put this code into it.

    $modelXmlPath = Read-Host "model.xml file path"
    $hasher = [System.Security.Cryptography.HashAlgorithm]::Create("System.Security.Cryptography.SHA256CryptoServiceProvider")
    $fileStream = new-object System.IO.FileStream ` -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open)
    $hash = $hasher.ComputeHash($fileStream)
    $hashString = ""
    Foreach ($b in $hash) { $hashString += $b.ToString("X2") }
    $fileStream.Close()
    $hashString
    

  • 运行PowerShell脚本,并为其提供已解压缩和编辑的model.xml文件的文件路径.它将返回一个校验和值.

  • Run the PowerShell script and give it the filepath to your unzipped and edited model.xml file. It will return a checksum value.

    复制校验和值,然后打开Origin.xml并替换现有的校验和,朝向如下所示的行的底部:

    Copy the checksum value, then open up Origin.xml and replace the existing checksum, toward the bottom on the line that looks like this:

    <Checksum Uri="/model.xml">9EA0F06B282D4F42955C78A98822A31AA0ED0225CB131B8759379055A482D01F</Checksum>
    

  • 保存并关闭Origin.xml,然后选择所有文件并将其放入新的zip文件中,并将扩展名重命名为bacpac.

  • Save and close Origin.xml, then select all the files and put them into a new zip file and rename the extension to bacpac.

    现在,您可以使用这个新的bacpac导入数据库,而不会出现错误.它对我有用,它也对你有用.

    Now you can use this new bacpac to import the database without getting the error. It worked for me, it could work for you, too.

    这篇关于将Azure bacpac文件导入本地db时出错,错误语法在EXTERNAL附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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