如何将示例bacpac文件导入到Azure SQL数据库

介绍 (Introduction)

In SQL Server 2000, the sample databases were pubs and northwind. They contained sample information to learn SQL Server.

在SQL Server 2000中,示例数据库为pubs和northwind 。 它们包含用于学习SQL Server的示例信息。

Starting in SQL Server 2005, the Adventureworks was the new Sample Database. Each SQL version (2005, 2008, 2012, 2014 and now 2016) included new samples included to show new features. In Adventureworks there were different adventurework versions:

从SQL Server 2005开始,Adventureworks是新的示例数据库。 每个SQL版本(2005、2008、2012、2014和现在的2016)都包含新的示例,以显示新功能。 在Adventureworks中,有不同的Adventurework版本:

  • OLTP version (Adventureworks for transactional databases)

    OLTP版本(用于事务数据库的Adventureworks)
  • Datawarehouse (AdventureworksDW for business intelligence including SSAS)

    数据仓库(AdventureworksDW,用于包括SSAS的商业智能)
  • Lite version (AdventureworksLT, a light transactional database)

    精简版(AdventureworksLT,轻型事务数据库)

In SQL Server 2016, a new sample database came:

在SQL Server 2016中,出现了一个新的示例数据库:

WideWorldImporters contains a real life database following design recommendations.

WideWorldImporters包含遵循设计建议的真实数据库。

This time we will talk about WideWorldImporters for Azure. This Database is a new database to work with Azure. By default, you can install the AdventureLT Database, however, it is now possible to import the WideWorldImporters to Azure.

这次,我们将讨论Azure的WideWorldImporters。 该数据库是与Azure一起使用的新数据库。 默认情况下,您可以安装AdventureLT数据库,但是现在可以将WideWorldImporters导入到Azure。

We will explain how to import WideWorldImporters, but the instructions are valid for any bacpac file.

我们将说明如何导入WideWorldImporters,但说明对任何bacpac文件均有效。

A bacpac file is the extension to deploy Data Tier Application packages.

bacpac文件是部署数据层应用程序软件包的扩展。

要求 (Requirements)

  1. SSMS in a local machine or Virtual machine.

    本地计算机或虚拟机中的SSMS。
  2. An Azure Account to the Azure Portal.

    Azure门户的Azure帐户
  3. MASE (Microsoft Azure Storage Explorer)

    MASE (Microsoft Azure存储资源管理器)

入门 (Getting started)

To import the WideWorldImporters database, we will explain two methods:

要导入WideWorldImporters数据库,我们将说明两种方法:

  1. Importing using the Portal and MASE
    1. In Azure Portal, create a storage account.
    2. Using MASE, create container and add the WideWorldImporters.pac file.
    3. In Azure Portal, import the file.

    使用门户网站和MASE导入
    1. 在Azure Portal中,创建一个存储帐户。
    2. 使用MASE创建容器,并添加WideWorldImporters.pac文件。
    3. 在Azure Portal中,导入文件。
  2. Another method is using SQL Server Management Studio (SSMS). This option is great if you have SSMS already installed.

    另一种方法是使用SQL Server Management Studio(SSMS)。 如果您已经安装了SSMS,则此选项非常有用。

方法1.使用Azure Portal和MASE导入数据库 (Method 1. Importing a database using Azure Portal and MASE)

This option is recommended if you do not have a local machine with SSMS. You only need MASE (which can be installed in a MAC, Windows and Linux machine).

如果您没有本地计算机使用SSMS,则建议使用此选项。 您只需要MASE(可以安装在MAC,Windows和Linux计算机中)。

First, in Azure Portal, go to New>Data+Storage>Storage Account and create a storage account. Storage account is used to store files, messages, etc. For more information about storage account, please refer to our article about MASE.

首先,在Azure门户中,转到“新建”>“数据+存储”>“存储帐户”并创建一个存储帐户。 存储帐户用于存储文件,消息等。有关存储帐户的更多信息,请参阅有关MASE的文章。

如何将示例bacpac文件导入到Azure SQL数据库

In MASE, connect to the storage account in figure 1 and create a container named mybackups or any name of your preference:

在MASE中,连接到图1中的存储帐户,然后创建一个名为mybackups或您的首选项的名称的容器:

如何将示例bacpac文件导入到Azure SQL数据库

Download the Azure WideWorldImporters-Standard.bacpac file.

下载Azure WideWorldImporters-Standard.bacpac文件。

In MASE, Upload the WideWorldImporters-Standard.bacpac just downloaded in the container created in figure 2:

在MASE中,上载刚刚在图2中创建的容器中下载的WideWorldImporters-Standard.bacpac:

如何将示例bacpac文件导入到Azure SQL数据库

In Azure Portal, go to more Services ➜ SQL Servers

在Azure门户中,转到更多服务➜SQL Server

如何将示例bacpac文件导入到Azure SQL数据库

Press Add to create a new SQL Server. Add a name, password and a group in Azure to create a new SQL Server:

按添加以创建一个新SQL Server。 在Azure中添加名称,密码和组以创建新SQL Server:

如何将示例bacpac文件导入到Azure SQL数据库

Select the database created and click Import Databases:

选择创建的数据库,然后单击导入数据库:

如何将示例bacpac文件导入到Azure SQL数据库

Select your subscription (this is important when you have multiple subscriptions):

选择您的订阅(当您有多个订阅时,这很重要):

如何将示例bacpac文件导入到Azure SQL数据库

Select the storage account created in Figure 1 and the container created in figure 2:

选择图1中创建的存储帐户和图2中创建的容器:

如何将示例bacpac文件导入到Azure SQL数据库

Select the file WideWorldImporters-Standard.bacpac uploaded on step 3:

选择在步骤3上传的文件WideWorldImporters-Standard.bacpac。

如何将示例bacpac文件导入到Azure SQL数据库

Specify a database name, login and password for the database and press OK:

指定数据库的数据库名称,登录名和密码,然后按确定:

如何将示例bacpac文件导入到Azure SQL数据库

To verify in your local SSMS, in Azure Portal, select the SQL Server and go to properties. Add the current client IP and Save:

若要在本地SSMS中进行验证,请在Azure门户中选择SQL Server并转到属性。 添加当前客户端IP并保存:

如何将示例bacpac文件导入到Azure SQL数据库


In your local machine, you can connect to the Azure database already created:

在本地计算机上,可以连接到已经创建的Azure数据库:

如何将示例bacpac文件导入到Azure SQL数据库

If everything is fine, you will be able to access to the WideWorldImporters-Standard database:

如果一切正常,您将可以访问WideWorldImporters-Standard数据库:

如何将示例bacpac文件导入到Azure SQL数据库

方法2。使用SSMS导入 (Method 2. Importing using SSMS)

This method is recommended if you have SSMS installed in a local machine. You do not need MASE if you import from a local file.

如果在本地计算机上安装了SSMS,则建议使用此方法。 如果从本地文件导入,则不需要MASE。

Another way to do import the file in Azure is in SSMS using the Import Data-tier Application. In you Azure Machine, right click and select this option:

在Azure中导入文件的另一种方法是在SSMS中使用导入数据层应用程序。 在您的Azure计算机中,右键单击并选择以下选项:

如何将示例bacpac文件导入到Azure SQL数据库

A wizard will be displayed:

将显示一个向导:

如何将示例bacpac文件导入到Azure SQL数据库

You can download the bacpac file to your machine with SSMS and import from the local file:

您可以使用SSMS将bacpac文件下载到计算机上,然后从本地文件导入:

如何将示例bacpac文件导入到Azure SQL数据库

Another option is to import from an Azure Account. To do it, you need to connect the Azure Account by pressing connect:

另一个选项是从Azure帐户导入。 为此,您需要通过按connect连接Azure帐户:

如何将示例bacpac文件导入到Azure SQL数据库

We will connect to Azure. In the MASE, you can find the storage account name created in figure 1 and the primary key used to connect to the Azure Storage Account:

我们将连接到Azure。 在MASE中,您可以找到在图1中创建的存储帐户名称以及用于连接到Azure存储帐户的主键:

如何将示例bacpac文件导入到Azure SQL数据库


Use in Storage account the name of Figure 18 and the primary key as the account name:

在存储帐户中使用图18的名称,并使用主键作为帐户名称:

如何将示例bacpac文件导入到Azure SQL数据库

Select the container and file name of figure 2 and 3:

选择图2和3的容器和文件名:

如何将示例bacpac文件导入到Azure SQL数据库

In settings, you can specify the database name, the edition. Basic is the cheapest option and standard is the option by default. The most expensive option is premium.

在设置中,您可以指定数据库名称,版本。 默认情况下,基本选项是最便宜的选项,标准选项是标准选项。 最昂贵的选择是保费。

如何将示例bacpac文件导入到Azure SQL数据库

The summary will show all the options selected in the wizard:

摘要将显示向导中选择的所有选项:

如何将示例bacpac文件导入到Azure SQL数据库

The new WideWorldImporters cannot be imported in SSMS 2014. When I try to import from my SQL Server 2014 machine. I receive the error message that the model version ‘2.9’ is not supported:

无法在SSMS 2014中导入新的WideWorldImporters。当我尝试从SQL Server 2014计算机中导入时。 我收到以下错误消息:不支持模型版本“ 2.9”:

如何将示例bacpac文件导入到Azure SQL数据库

In SQL Server 2016, you will not receive errors, unless your internet connection is slow. I received the following error message when trying to import the data in a machine with slow internet connection:

在SQL Server 2016中,除非您的Internet连接速度慢,否则您不会收到错误。 尝试在互联网连接速度慢的计算机上导入数据时收到以下错误消息:

如何将示例bacpac文件导入到Azure SQL数据库

The error message says that a connection was successfully established with the server, but then an error occurred during the pre-login handshake. If you have this error, we recommend using the first method to import the database to Azure.

该错误消息表明已成功与服务器建立连接,但随后在登录前握手期间发生了错误。 如果出现此错误,我们建议使用第一种方法将数据库导入到Azure。

If your internet connection is fine and you have SSMS 2016 or later, everything should be fine:

如果您的互联网连接正常并且您拥有SSMS 2016或更高版本,那么一切都应该很好:

如何将示例bacpac文件导入到Azure SQL数据库

结论 (Conclusion)

In this article, we explained how to import a database to Azure. The first option is using the Portal and MASE. This option is recommended. The second option requires SSMS 2016 or later and it ofte fails with clients that have slow internet connections.

在本文中,我们解释了如何将数据库导入到Azure。 第一种选择是使用门户网站和MASE。 建议使用此选项。 第二个选项需要SSMS 2016或更高版本,并且对于Internet连接速度慢的客户端,它通常会失败。

翻译自: https://www.sqlshack.com/import-sample-bacpac-file-azure-sql-database/