升级应用以使用最新的弹性数据库客户端库Upgrade an app to use the latest elastic database client library

可通过 Visual Studio 中 NuGet 和 NuGet 包管理器界面获取弹性数据库客户端库的新版本。New versions of the Elastic Database client library are available through NuGet and the NuGet Package Manager interface in Visual Studio. 升级包含客户端库的 bug 修复和新功能支持。Upgrades contain bug fixes and support for new capabilities of the client library.

有关最新版本: 请转到 Microsoft.Azure.SqlDatabase.ElasticScale.ClientFor the latest version: Go to Microsoft.Azure.SqlDatabase.ElasticScale.Client.

使用新库重新生成应用程序,以及更改 Azure SQL 数据库中存储的现有分片映射管理器元数据以支持新功能。Rebuild your application with the new library, as well as change your existing Shard Map Manager metadata stored in your Azure SQL databases to support new features.

按顺序执行这些步骤可确保在更新元数据对象时,旧版本的客户端库不再存在于环境中,这意味着在升级后不会创建旧版本的元数据对象。Performing these steps in order ensures that old versions of the client library are no longer present in your environment when metadata objects are updated, which means that old-version metadata objects won't be created after upgrade.

升级步骤Upgrade steps

1.升级应用程序。1. Upgrade your applications. 在 Visual Studio 中,下载最新的客户端库版本并在使用该库的所有开发项目中引用该版本;并重新生成并部署。In Visual Studio, download and reference the latest client library version into all of your development projects that use the library; then rebuild and deploy.

  • 在 Visual Studio 解决方案中,选择“工具” --> “Nuget 程序包管理器” --> “管理解决方案的 Nuget 程序包”。In your Visual Studio solution, select Tools --> NuGet Package Manager --> Manage NuGet Packages for Solution.
  • (Visual Studio 2013) 在左侧面板中,选择“更新”,并选择窗口中显示的包“Azure SQL 数据库弹性扩展客户端库”上的“更新”按钮。(Visual Studio 2013) In the left panel, select Updates, and then select the Update button on the package Azure SQL Database Elastic Scale Client Library that appears in the window.
  • (Visual Studio 2015) 将“筛选器”框设置为“可用升级”。(Visual Studio 2015) Set the Filter box to Upgrade available. 选择要更新的包,并单击“更新” 按钮。Select the package to update, and click the Update button.
  • (Visual Studio 2017) 在对话框顶部,选择“更新”。 (Visual Studio 2017) At the top of the dialog, select Updates. 选择要更新的包,并单击“更新” 按钮。Select the package to update, and click the Update button.
  • 生成并部署。Build and Deploy.

2.升级脚本。2. Upgrade your scripts. 如果使用 PowerShell 脚本来管理分片,请下载新的库版本并将其复制到从中执行脚本的目录中。If you are using PowerShell scripts to manage shards, download the new library version and copy it into the directory from which you execute scripts.

3.升级拆分/合并服务。3. Upgrade your split-merge service. 如果使用弹性数据库拆分/合并工具来重新组织分片数据,请下载并部署最新版本的工具If you use the elastic database split-merge tool to reorganize sharded data, download and deploy the latest version of the tool. 可在此处找到该服务的详细升级步骤。Detailed upgrade steps for the Service can be found here.

4.升级分片映射管理器数据库4. Upgrade your Shard Map Manager databases. 升级 Azure SQL 数据库中支持分片映射的元数据。Upgrade the metadata supporting your Shard Maps in Azure SQL Database. 有两种方法可以完成此操作:使用 PowerShell 或 C#。There are two ways you can accomplish this, using PowerShell or C#. 这两个选项在下面说明。Both options are shown below.

选项 1:使用 PowerShell 升级元数据Option 1: Upgrade metadata using PowerShell

  1. 此处下载 NuGet 的最新命令行实用工具并将其保存到一个文件夹。Download the latest command-line utility for NuGet from here and save to a folder.
  2. 打开命令提示符,导航到同一文件夹,并发出命令: nuget install Microsoft.Azure.SqlDatabase.ElasticScale.ClientOpen a Command Prompt, navigate to the same folder, and issue the command: nuget install Microsoft.Azure.SqlDatabase.ElasticScale.Client
  3. 导航到包含刚下载的新客户端 DLL 版本的子文件夹,例如: cd .\Microsoft.Azure.SqlDatabase.ElasticScale.Client.1.0.0\lib\net45Navigate to the subfolder containing the new client DLL version you have just downloaded, for example: cd .\Microsoft.Azure.SqlDatabase.ElasticScale.Client.1.0.0\lib\net45
  4. 脚本中心下载弹性数据库客户端升级脚本,并将其保存到包含 DLL 的同一文件夹中。Download the elastic database client upgrade script from the Script Center, and save it into the same folder containing the DLL.
  5. 在命令提示符下从该文件夹运行“PowerShell .\upgrade.ps1”,并按照提示进行操作。From that folder, run "PowerShell .\upgrade.ps1" from the command prompt and follow the prompts.

选项 2:使用 C# 升级元数据Option 2: Upgrade metadata using C#

或者,创建一个 Visual Studio 应用程序,它打开 ShardMapManager,循环访问所有分片并通过调用 UpgradeLocalStoreUpgradeGlobalStore 方法执行元数据升级,如此示例所示:Alternatively, create a Visual Studio application that opens your ShardMapManager, iterates over all shards, and performs the metadata upgrade by calling the methods UpgradeLocalStore and UpgradeGlobalStore as in this example:

ShardMapManager smm =
   ShardMapManagerFactory.GetSqlShardMapManager
   (connStr, ShardMapManagerLoadPolicy.Lazy);
smm.UpgradeGlobalStore();

foreach (ShardLocation loc in
 smm.GetDistinctShardLocations())
{
   smm.UpgradeLocalStore(loc);
}

这些元数据升级技术可以应用多次而无危害。These techniques for metadata upgrades can be applied multiple times without harm. 例如,如果在已更新后,旧的客户端版本无意中创建了一个分片,可以对所有分片再次运行升级,以确保最新的元数据版本在整个基础结构中存在。For example, if an older client version inadvertently creates a shard after you have already updated, you can run upgrade again across all shards to ensure that the latest metadata version is present throughout your infrastructure.

注意: 到目前为止,发布的客户端库的新版本将继续使用 Azure SQL 数据库上早期版本的分片映射管理器元数据,反之亦然。Note: New versions of the client library published to-date continue to work with prior versions of the Shard Map Manager metadata on Azure SQL DB, and vice-versa. 但是,为了利用最新客户端中的一些新功能,需要对元数据进行升级。However to take advantage of some of the new features in the latest client, metadata needs to be upgraded. 请注意,元数据升级不会影响任何用户数据或特定于应用程序的数据,只会影响分片映射管理器创建和使用的对象。Note that metadata upgrades will not affect any user-data or application-specific data, only objects created and used by the Shard Map Manager. 并且应用程序将继续按照前面所述的升级顺序进行操作。And applications continue to operate through the upgrade sequence described above.

弹性数据库客户端版本历史记录Elastic database client version history

有关版本历史记录,请转到 Microsoft.Azure.SqlDatabase.ElasticScale.ClientFor version history, go to Microsoft.Azure.SqlDatabase.ElasticScale.Client

其他资源Additional resources

尚未使用弹性数据库工具?Not using elastic database tools yet? 请查看入门指南Check out our Getting Started Guide.