使用 Azure 存储资源管理器处理数据Work with data using Azure Storage Explorer

通过在 Azure 存储资源管理器中使用 Azure Cosmos DB,用户可以管理 Azure Cosmos DB 实体、操作数据、更新存储过程和触发器以及其他 Azure 实体(如存储 blob 和队列)。Using Azure Cosmos DB in Azure Storage Explorer enables users to manage Azure Cosmos DB entities, manipulate data, update stored procedures and triggers along with other Azure entities like Storage blobs and queues. 现在可以使用相同工具在一个位置管理不同 Azure 实体。Now you can use the same tool to manage your different Azure entities in one place. 目前,Azure 存储资源管理器支持为 SQL 和 MongoDB 配置的 Cosmos 帐户。At this time, Azure Storage Explorer supports Cosmos accounts configured for SQL, MongoDB.

先决条件Prerequisites

具有采用了 SQL API 或 Azure Cosmos DB 的用于 MongoDB 的 API 的 Cosmos 帐户。A Cosmos account with SQL API or Azure Cosmos DB's API for MongoDB. 如果你没有帐户,则可以按照 Azure Cosmos DB:使用 .NET 和 Azure 门户生成 SQL API Web 应用中所述,在 Azure 门户中创建一个。If you don't have an account, you can create one in the Azure portal, as described in Azure Cosmos DB: Build a SQL API web app with .NET and the Azure portal.

安装Installation

在此处安装最新 Azure 存储资源管理器 BITS:Azure 存储资源管理器,现在我们支持 Windows、Linux 和 MAC 版本。Install the newest Azure Storage Explorer bits here: Azure Storage Explorer, now we support Windows, Linux, and MAC version.

连接到 Azure 订阅Connect to an Azure subscription

  1. 安装 Azure 存储资源管理器之后,单击左侧的插件图标,如下图中所示:After installing the Azure Storage Explorer, click the plug-in icon on the left as shown in the following image:

    插件图标

  2. 在“添加 Azure 帐户”中选择值“Azure 中国”,然后单击“登录”。Select the value of Azure China in Add an Azure Account, and then click Sign-in.

    连接到 Azure 订阅 Connect to Azure subscription

  3. 在“Azure 登录”对话框中,选择“登录”,然后输入 Azure 凭据。In the Azure Sign in dialog box, select Sign in, and then enter your Azure credentials.

    登录

  4. 从列表中选择你的订阅,然后单击“应用”。Select your subscription from the list and then click Apply.

    应用

    资源管理器窗格会更新,并显示所选订阅中的帐户。The Explorer pane updates and displays the accounts in the selected subscription.

    帐户列表

    现已成功将 Cosmos DB 帐户连接到 Azure 订阅。You have successfully connected to your Cosmos DB account to your Azure subscription.

使用连接字符串连接到 Azure Cosmos DBConnect to Azure Cosmos DB by using a connection string

连接到 Azure Cosmos DB 的一种替代方法是使用连接字符串。An alternative way of connecting to an Azure Cosmos DB is to use a connection string. 按照以下步骤可使用连接字符串进行连接。Use the following steps to connect using a connection string.

  1. 在左侧树中找到“本地和附加”,右键单击“Cosmos DB 帐户”,然后选择“连接到 Cosmos DB...”Find Local and Attached in the left tree, right-click Cosmos DB Accounts, choose Connect to Cosmos DB...

    通过连接字符串连接到 Cosmos DB

  2. 目前仅支持 SQL API。Only support SQL API currently. 选择“API”,粘贴连接字符串,输入帐户标签,单击“下一步”查看摘要,然后单击“连接”以连接 Azure Cosmos DB 帐户。Choose API, paste Connection String, input Account label, click Next to check the summary, and then click Connect to connect Azure Cosmos DB account. 有关检索连接字符串的信息,请参阅获取连接字符串For information on retrieving the connection string, see Get the connection string.

    连接字符串

使用本地模拟器连接到 Azure Cosmos DBConnect to Azure Cosmos DB by using local emulator

使用以下步骤通过模拟器连接到 Azure Cosmos DB(目前仅支持 SQL 帐户)。Use the following steps to connect to an Azure Cosmos DB by Emulator, only support SQL account currently.

  1. 安装并启动模拟器。Install Emulator and launch. 有关如何安装模拟器的信息,请参阅 Cosmos DB 模拟器For how to install Emulator, see Cosmos DB Emulator

  2. 在左侧树中找到“本地和附加”,右键单击“Cosmos DB 帐户”,然后选择“连接到 Cosmos DB 模拟器...”Find Local and Attached in the left tree, right-click Cosmos DB Accounts, choose Connect to Cosmos DB Emulator...

    通过模拟器连接到 Cosmos DB

  3. 目前仅支持 SQL API。Only support SQL API currently. 粘贴连接字符串,输入帐户标签,单击“下一步”查看摘要,然后单击“连接”以连接 Azure Cosmos DB 帐户。Paste Connection String, input Account label, click Next to check the summary, and then click Connect to connect Azure Cosmos DB account. 有关检索连接字符串的信息,请参阅获取连接字符串For information on retrieving the connection string, see Get the connection string.

    通过模拟器对话框连接到 Cosmos DB

Azure Cosmos DB 资源管理Azure Cosmos DB resource management

你可以通过执行以下操作来管理 Azure Cosmos DB 帐户:You can manage an Azure Cosmos DB account by doing following operations:

  • 在 Azure 门户中打开帐户Open the account in the Azure portal
  • 将资源添加到快速访问列表Add the resource to the Quick Access list
  • 搜索和刷新资源Search and refresh resources
  • 创建和删除数据库Create and delete databases
  • 创建和删除集合Create and delete collections
  • 创建、编辑、删除和筛选文档Create, edit, delete, and filter documents
  • 管理存储过程、触发器和用户定义的函数Manage stored procedures, triggers, and user-defined functions

快速访问任务Quick access tasks

通过在资源管理器窗格中右键单击订阅,可以执行许多快速操作任务:By right-clicking on a subscription in the Explorer pane, you can perform many quick action tasks:

  • 右键单击 Azure Cosmos DB 帐户或数据库,可以选择“在门户中打开”,然后在 Azure 门户上通过浏览器管理资源。Right-click an Azure Cosmos DB account or a database, you can choose Open in Portal and manage the resource in the browser on the Azure portal.

    在门户中打开

  • 还可以将 Azure Cosmos DB 帐户、数据库、集合添加到“快速访问”。You can also add Azure Cosmos DB account, database, collection to Quick Access.

  • 通过“从此处搜索”可以在所选路径下进行关键字搜索。Search from Here enables keyword search under the selected path.

    从此处搜索

数据库和集合管理Database and collection management

创建数据库Create a database

  • 右键单击 Azure Cosmos DB 帐户,选择“创建数据库”,输入数据库名称,然后按 Enter 以完成。Right-click the Azure Cosmos DB account, choose Create Database, input the database name, and press Enter to complete.

    创建数据库

删除数据库Delete a database

  • 右键单击数据库,单击“删除数据库”,然后在弹出窗口中单击“是”。Right-click the database, click Delete Database, and click Yes in the pop-up window. 数据库节点会删除,并且 Azure Cosmos DB 帐户会自动刷新。The database node is deleted, and the Azure Cosmos DB account refreshes automatically.

    删除数据库 1

    删除数据库 2

创建集合Create a collection

  1. 右键单击数据库,选择“创建集合”,然后提供以下信息,如“集合 ID”、“存储容量”等。单击“确定”完成。Right-click your database, choose Create Collection, and then provide the following information like Collection ID, Storage capacity, etc. Click OK to finish.

    创建集合 1

    创建集合 2

  2. 选择“无限制”以便能够指定分区键,然后单击“确定”完成操作。Select Unlimited to be able to specify partition key, then click OK to finish.

    如果在创建集合时使用分区键,则一旦创建完成,便无法对集合更改分区键值。If a partition key is used when creating a collection, once creation is completed, the partition key value can't be changed on the collection.

    分区键

删除集合Delete a collection

  • 右键单击集合,单击“删除集合”,然后在弹出窗口中单击“是”。Right-click the collection, click Delete Collection, and then click Yes in the pop-up window.

    集合节点会删除,并且数据库会自动刷新。The collection node is deleted, and the database refreshes automatically.

    删除集合

文档管理Document management

创建和修改文档Create and modify documents

  • 若要创建新文档,请打开左窗口中的“文档”,单击“新建文档”,在右窗格中编辑内容,然后单击“保存”。To create a new document, open Documents in the left window, click New Document, edit the contents in the right pane, then click Save. 还可以更新现有文档,然后单击“保存”。You can also update an existing document, and then click Save. 可以通过单击“放弃”来放弃更改。Changes can be discarded by clicking Discard.

    文档

删除文档Delete a document

  • 单击“删除”按钮以删除所选文档。Click the Delete button to delete the selected document.

查询文档Query for documents

  • 通过输入 SQL 查询来编辑文档筛选器,然后单击“应用”。Edit the document filter by entering a SQL query and then click Apply.

    文档筛选器

管理存储过程、触发器和 UDFManage stored procedures, triggers, and UDFs

  • 若要创建存储过程,请在左侧树中,右键单击“存储过程”,选择“创建存储过程”,在左侧输入名称,在右侧窗口中输入存储过程脚本,然后单击“创建”。To create a stored procedure, in the left tree, right-click Stored Procedure, choose Create Stored Procedure, enter a name in the left, type the stored procedure scripts in the right window, and then click Create.

  • 还可以双击,进行更新,然后单击“更新”保存,从而编辑现有存储过程,或单击“放弃”以取消更改。You can also edit existing stored procedures by double-clicking, making the update, and then clicking Update to save, or click Discard to cancel the change.

    存储过程

  • 适用于触发器UDF 的操作与存储过程类似。The operations for Triggers and UDF are similar with Stored Procedures.

故障排除Troubleshooting

Azure 存储资源管理器中的 Azure Cosmos DB 是一个独立的应用,用于连接到 Azure Cosmos DB 帐户,而该帐户托管在 Windows、macOS 或 Linux 版本的 Azure 和主权云上。Azure Cosmos DB in Azure Storage Explorer is a standalone app that allows you to connect to Azure Cosmos DB accounts hosted on Azure and Sovereign Clouds from Windows, macOS, or Linux. 它可以用来管理 Azure Cosmos DB 实体、操作数据、更新存储过程和触发器以及其他 Azure 实体(如存储 Blob 和队列)。It enables you to manage Azure Cosmos DB entities, manipulate data, update stored procedures and triggers along with other Azure entities like Storage blobs and queues.

以下解决方案适用于存储资源管理器中 Azure Cosmos DB 的常见问题。These are solutions for common issues seen for Azure Cosmos DB in Storage Explorer.

登录问题Sign in issues

继续之前,请尝试重启应用程序,看问题是否能够解决。Before proceeding further, try restarting your application and see if the problems can be fixed.

证书链中的自签名证书Self-signed certificate in certificate chain

出现此错误有多个原因,最常见的两个原因是:There are a few reasons you may be seeing this error, the two most common ones are:

  • 你位于“透明代理”之后,这意味着某人(例如 IT 部门)在拦截 HTTPS 流量,将其解密后又使用自签名证书对其加密。You're behind a transparent proxy, which means someone (such as your IT department) is intercepting HTTPS traffic, decrypting it, and then encrypting it using a self-signed certificate.

  • 正在运行的软件(如防病毒软件)在向收到的 HTTPS 消息注入自签名 SSL 证书。You're running software, such as anti-virus software, which is injecting a self-signed SSL certificates into the HTTPS messages you receive.

存储资源管理器在遇到其中一个这样的“自签名证书”时,将再也无法判断收到的 HTTPS 消息是否已被篡改。When Storage Explorer encounters one of these "self-signed certificates", it can no longer know if the HTTPS message it's receiving has been tampered with. 但若拥有一份自签名证书的副本,则可让存储资源管理器信任它。If you have a copy of the self-signed certificate though, then you can tell Storage Explorer to trust it. 若无法确定谁在注入证书,则可自行尝试通过以下步骤找到它:If you're unsure of who is injecting the certificate, then you can try to find it yourself by doing the following steps:

  1. 安装 Open SSLInstall Open SSL
    • Windows(任意轻量版本均可)Windows (any of the light versions is ok)
    • Mac 和 Linux:应包含在操作系统中Mac and Linux: Should be included with your operating system
  2. 运行 Open SSLRun Open SSL
    • Windows:转到安装目录,然后转到“/bin/”,然后双击“openssl.exe”。Windows: Go to the install directory, then /bin/, then double-click on openssl.exe.
    • Mac 和 Linux:从终端执行“openssl”Mac and Linux: execute openssl from a terminal
  3. 执行 s_client -showcerts -connect microsoft.com:443Execute s_client -showcerts -connect microsoft.com:443
  4. 查找自签名证书。Look for self-signed certificates. 若不确定哪个证书为自签名,则请查找使用者(“s:”)和证书颁发者(“i:”)相同的任意位置。If you're unsure, which are self-signed, then look for anywhere the subject ("s:") and issuer ("i:") are the same.
  5. 找到任何自签名证书后,将每个证书中从“-----BEGIN CERTIFICATE-----”(含)到“-----END CERTIFICATE-----”(含)的部分复制和粘贴到新的 .cer 文件。Once you have found any self-signed certificates, copy and paste everything from and including -----BEGIN CERTIFICATE----- to -----END CERTIFICATE----- to a new .cer file for each one.
  6. 打开存储资源管理器,然后转到“编辑” > “SSL 证书” > “导入证书”。Open Storage Explorer and then go to Edit > SSL Certificates > Import Certificates. 使用文件选取器查找、选择和打开所创建的 .cer 文件。Using the file picker, find, select, and open the .cer files you created.

若通过上述步骤无法找到任何自签名证书,可通过发送反馈以获取更多帮助。If you're unable to find any self-signed certificates using the above steps, could send feedback for more help.

无法检索订阅Unable to retrieve subscriptions

若成功登录后无法检索订阅,请执行以下操作:If you're unable to retrieve your subscriptions after you successfully signed in:

  • 通过登录 Azure 门户验证帐户是否有权访问该订阅Verify your account has access to the subscriptions by signing into the Azure Portal

  • 确保已使用正确的环境(Azure 中国或自定义环境/Azure Stack)登录Make sure you have signed in using the correct environment (Azure China, or Custom Environment/Azure Stack)

  • 如果使用代理,请确保已正确配置存储资源管理器代理If you're behind a proxy, make sure that you have configured the Storage Explorer proxy properly

  • 尝试移除并重新添加帐户Try removing and readding the account

  • 尝试从主目录删除以下文件(例如:C:\Users\ContosoUser),然后重新添加帐户:Try deleting the following files from your home directory (such as: C:\Users\ContosoUser), and then readding the account:

    • .adalcache.adalcache
    • .devaccounts.devaccounts
    • .extaccounts.extaccounts
  • 登录查询任何错误消息时,请查看开发人员工具控制台(F12)Watch the developer tools console (f12) while signing in for any error messages

    console

无法查看身份验证页Unable to see the authentication page

如果无法看到身份验证页面:If you're unable to see the authentication page:

  • 根据连接速度不同,加载登录页面可能需要一会儿,请至少等待一分钟再关闭身份验证对话框Depending on the speed of your connection, it may take a while for the sign-in page to load, wait at least one minute before closing the authentication dialog
  • 如果使用代理,请确保已正确配置存储资源管理器代理If you're behind a proxy, make sure that you have configured the Storage Explorer proxy properly
  • 按 F12 键显示开发人员控制台。Bring up the developer console by pressing F12 key. 从开发人员控制台查看响应,看能否找到身份验证不起作用的任何线索Watch the responses from developer console and see if you can find any clue for why authentication is not working

无法删除帐户Cannot remove account

如果无法移除帐户,或重新验证链接不起作用If you're unable to remove an account, or if the reauthenticate link does not do anything

  • 尝试从主目录删除以下文件,然后重新添加帐户:Try deleting the following files from your home directory, and then readding the account:
    • .adalcache.adalcache
    • .devaccounts.devaccounts
    • .extaccounts.extaccounts
  • 若要删除附加了 SAS 的存储资源,请删除:If you want to remove SAS attached Storage resources, delete:
    • %AppData%/StorageExplorer 文件夹(对于 Windows)%AppData%/StorageExplorer folder for Windows
    • Mac 中的 /Users/<your_name>/Library/Application SUpport/StorageExplorer/Users/<your_name>/Library/Application SUpport/StorageExplorer for Mac
    • ~/.config/StorageExplorer(对于 Linux)~/.config/StorageExplorer for Linux
    • 删除这些文件之后,需要重新输入所有凭据You will have to reenter all your credentials if you delete these files

Http/Https 代理问题Http/Https proxy issue

在 ASE 中配置 http/https 代理时,无法列出左侧树中的 Azure Cosmos DB 节点。You cannot list Azure Cosmos DB nodes in left tree when configuring http/https proxy in ASE. 这是一个已知问题,下一版本会修复此问题。It's a known issue, and will be fixed in next release. 目前可以在 Azure 门户中使用 Azure Cosmos DB 数据资源管理器作为解决方法。You could use Azure Cosmos DB data explorer in Azure portal as a work-around at this moment.

“本地和附加”节点下的“开发”节点问题"Development" node under "Local and Attached" node issue

在左侧树中单击“本地和附加”节点下的“开发”节点时没有响应。There is no response after clicking the "Development" node under "Local and Attached" node in left tree. 此行为是预期的行为。The behavior is expected. 下一版本会支持 Azure Cosmos DB 本地模拟器。Azure Cosmos DB local emulator will be supported in next release.

开发节点

在“本地和附加”节点中附加 Azure Cosmos DB 帐户错误Attaching Azure Cosmos DB account in "Local and Attached" node error

如果在“本地和附加”节点中附加 Azure Cosmos DB 帐户时看到以下错误,则请检查是否使用了正确的连接字符串。If you see below error after attaching Azure Cosmos DB account in "Local and Attached" node, then check if you're using the right connection string.

在“本地和附加”中附加 Azure Cosmos DB 错误

展开 Azure Cosmos DB 节点错误Expand Azure Cosmos DB node error

尝试展开左侧的树节点时可能会看到以下错误。You may see below error while trying to expand the tree nodes in left.

展开错误

请尝试以下建议:Try the following suggestions:

  • 检查 Azure Cosmos DB 帐户是否正在进行预配,然后在帐户成功创建以后再次进行尝试。Check if the Azure Cosmos DB account is in provision progress and try again when the account is being created successfully.
  • 如果帐户位于“快速访问”节点或“本地和附加”节点下,则请检查该帐户是否已删除。If the account is under "Quick Access" node or "Local and Attached" nodes, then check if the account has been deleted. 如果是这样,则需手动删除节点。If so, you need to remove the node manually.

联系我们Contact us

如果以上解决方案均不起作用,请向 Azure Cosmos DB 开发人员工具团队(Azure 支持)发送电子邮件,对问题进行详细说明,以便解决问题。If none of the solutions work for you, send email to Azure Cosmos DB Dev Tooling Team (Azure Support with details about the issue, for fixing the issues.

后续步骤Next steps