在 Azure 存储模拟器中创建 Table 会产生 HTTP 500 错误
Creating Table in Azure Storage Emulator produces HTTP 500 Error
我一直在尝试通过我机器的 Azure 存储模拟器创建 table。我可以使用仅使用 WindowsAzure.Storage nuget 版本 6.2.0 的非常简单的程序重现该问题:
using Microsoft.WindowsAzure.Storage;
namespace StorageEmulatorTest
{
internal class Program
{
private static void Main(string[] args)
{
var cloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
cloudTableClient.GetTableReference("JohnnyTest").CreateIfNotExists();
}
}
}
25 秒后,这将抛出类型为 Microsoft.WindowsAzure.Storage.StorageException
的异常,仅包含以下消息:
The remote server returned an error: (500) Internal Server Error.
我尝试过:
- 确保我的 WindowsAzure.Storage nuget 包是最新版本 (6.2.0)。
- 重新安装 Azure SDK for VS2015 2.8.1(并确保它是最新版本)
- 通过 Azure 存储模拟器命令行工具停止、清除、启动 Azure 存储模拟器(似乎工作正常,没有错误)
- 通过异常的“.InnerException.Response.GetResponseStream()”读取网络响应流。这失败了,异常显示 "Stream was not readable".
- 重新启动我的机器(绝望开始了)
我的技巧包 运行 很少。有人遇到过这个问题吗?
我解决了。我不得不彻底清除现有的本地存储仿真实例。使用 "AzureStorageEmulator.exe clear" 或 "AzureStorageEmulator.exe init" 是不够的。即使卸载 Azure SDK 也不够。
我首先停止了存储模拟:
AzureStorageEmulator.exe stop
AzureStorageEmulator.exe clear
AzureStorageEmulator.exe init /forceCreate
最后一条命令出错,表明它无法创建数据库。
然后我删除了(实际上,我重命名了它们)这些剩余的文件构成了 Azure 存储模拟器背后的数据库:
- C:\用户\[我]\AzureStorageEmulatorDb42_log.ldf
- C:\用户\[我]\AzureStorageEmulatorDb42_log.mdf
最后,我重新启动了模拟器
AzureStorageEmulator.exe init /forceCreate
AzureStorageEmulator.exe start
成功!
我不确定是什么让我陷入困境,但我最好的猜测是这是由最近升级的 Azure SDK 引起的。
我认为在很多情况下,Johnny 的回答可以解决问题。
在我的例子中,这也不起作用,因为 AzStorageEmulator 没有创建数据库 AzureStorageEmulator510
(数据库实例 (localdb)\MSSQLLocalDB
),也没有创建其中的表。
所以我使用 SSMS 从头开始创建数据库 AzureStorageEmulator510
,
然后我发现旧版本 AzureStorageEmulator57
还在我的电脑上,所以我附加了它(你可以在 C:\Users\YOURACCOUNT
中找到数据库)- 将数据库结构提取到 SQL 脚本和 运行 AzureStorageEmulator510
.
之后,我启动了模拟器并使用 AzStorageExplorer 创建了一个新的 blob 容器。
错误 500 似乎是因为该数据库(和内部结构)丢失并且无法通过 CLI 命令重新创建 AzureStorageEmulator.exe init /forceCreate
。
您可以检查的其他事项(可能的问题):
也可能是AzStorageEmulator无法访问其数据库。 here.
描述了原因之一(以及如何解决)
安装较新版本的实例后(localdb)\MSSQLLocalDB
,可能是没有附加相关数据库。这将导致 st运行ge 错误,如
Cannot open database "AzureStorageEmulator510" requested by the login. The login failed. Login failed for user 'YOURACCOUNT'.
如果是这种情况,您可以通过简单地通过 SSMS 连接到 localDb 来修复它,然后 attach 数据库:右键单击数据库,select Attach...
in上下文菜单,然后在对话框中,添加数据库文件(位于 C:\Users\YOURACCOUNT
)。
我一直在尝试通过我机器的 Azure 存储模拟器创建 table。我可以使用仅使用 WindowsAzure.Storage nuget 版本 6.2.0 的非常简单的程序重现该问题:
using Microsoft.WindowsAzure.Storage;
namespace StorageEmulatorTest
{
internal class Program
{
private static void Main(string[] args)
{
var cloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
cloudTableClient.GetTableReference("JohnnyTest").CreateIfNotExists();
}
}
}
25 秒后,这将抛出类型为 Microsoft.WindowsAzure.Storage.StorageException
的异常,仅包含以下消息:
The remote server returned an error: (500) Internal Server Error.
我尝试过:
- 确保我的 WindowsAzure.Storage nuget 包是最新版本 (6.2.0)。
- 重新安装 Azure SDK for VS2015 2.8.1(并确保它是最新版本)
- 通过 Azure 存储模拟器命令行工具停止、清除、启动 Azure 存储模拟器(似乎工作正常,没有错误)
- 通过异常的“.InnerException.Response.GetResponseStream()”读取网络响应流。这失败了,异常显示 "Stream was not readable".
- 重新启动我的机器(绝望开始了)
我的技巧包 运行 很少。有人遇到过这个问题吗?
我解决了。我不得不彻底清除现有的本地存储仿真实例。使用 "AzureStorageEmulator.exe clear" 或 "AzureStorageEmulator.exe init" 是不够的。即使卸载 Azure SDK 也不够。
我首先停止了存储模拟:
AzureStorageEmulator.exe stop
AzureStorageEmulator.exe clear
AzureStorageEmulator.exe init /forceCreate
最后一条命令出错,表明它无法创建数据库。
然后我删除了(实际上,我重命名了它们)这些剩余的文件构成了 Azure 存储模拟器背后的数据库:
- C:\用户\[我]\AzureStorageEmulatorDb42_log.ldf
- C:\用户\[我]\AzureStorageEmulatorDb42_log.mdf
最后,我重新启动了模拟器
AzureStorageEmulator.exe init /forceCreate
AzureStorageEmulator.exe start
成功!
我不确定是什么让我陷入困境,但我最好的猜测是这是由最近升级的 Azure SDK 引起的。
我认为在很多情况下,Johnny 的回答可以解决问题。
在我的例子中,这也不起作用,因为 AzStorageEmulator 没有创建数据库 AzureStorageEmulator510
(数据库实例 (localdb)\MSSQLLocalDB
),也没有创建其中的表。
所以我使用 SSMS 从头开始创建数据库 AzureStorageEmulator510
,
然后我发现旧版本 AzureStorageEmulator57
还在我的电脑上,所以我附加了它(你可以在 C:\Users\YOURACCOUNT
中找到数据库)- 将数据库结构提取到 SQL 脚本和 运行 AzureStorageEmulator510
.
之后,我启动了模拟器并使用 AzStorageExplorer 创建了一个新的 blob 容器。
错误 500 似乎是因为该数据库(和内部结构)丢失并且无法通过 CLI 命令重新创建 AzureStorageEmulator.exe init /forceCreate
。
您可以检查的其他事项(可能的问题):
也可能是AzStorageEmulator无法访问其数据库。 here.
描述了原因之一(以及如何解决)安装较新版本的实例后
(localdb)\MSSQLLocalDB
,可能是没有附加相关数据库。这将导致 st运行ge 错误,如
Cannot open database "AzureStorageEmulator510" requested by the login. The login failed. Login failed for user 'YOURACCOUNT'.
如果是这种情况,您可以通过简单地通过 SSMS 连接到 localDb 来修复它,然后 attach 数据库:右键单击数据库,selectAttach...
in上下文菜单,然后在对话框中,添加数据库文件(位于C:\Users\YOURACCOUNT
)。