Search code examples
c#azurelocaldbazure-storage-emulator

Creating Table in Azure Storage Emulator produces HTTP 500 Error


I've been attempting to create a table through my machine's Azure storage emulator. I can recreate the problem with a very simple program that uses only WindowsAzure.Storage nuget version 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();
        }
    }
}

After 25 seconds, this will throw an exception of type Microsoft.WindowsAzure.Storage.StorageException with only this message:

The remote server returned an error: (500) Internal Server Error.

I have attempted:

  1. Ensuring my WindowsAzure.Storage nuget package is the latest version (6.2.0).
  2. Re-installing the Azure SDK for VS2015 2.8.1 (and ensuring that it's the latest version)
  3. Stopping, clearing, initing the Azure Storage Emulator through the Azure Storage Emulator command line tool (seemed to work fine, no errors)
  4. Reading the web response's stream through the exception's ".InnerException.Response.GetResponseStream()". This fails with an exception that states "Stream was not readable".
  5. Restarting my machine (desperation kicked in)

My bag of tricks is running low. Has anybody encountered this issue?


Solution

  • I solved it. I had to completely wipe out my existing local storage emulation instance. Using "AzureStorageEmulator.exe clear" or "AzureStorageEmulator.exe init" was insufficient. Even uninstalling the Azure SDK was insufficient.

    I started by stopping the storage emulation:

    AzureStorageEmulator.exe stop
    AzureStorageEmulator.exe clear
    AzureStorageEmulator.exe init /forceCreate
    

    That last command errored and indicated that it could not create the database.

    Then I deleted (actually, I renamed them) these remaining files that comprised the database behind the azure storage emulator:

    • C:\Users\[Me]\AzureStorageEmulatorDb42_log.ldf
    • C:\Users\[Me]\AzureStorageEmulatorDb42_log.mdf

    Finally, I started the emulator back up

    AzureStorageEmulator.exe init /forceCreate
    AzureStorageEmulator.exe start
    

    Success!

    I'm unsure what got me into the situation, but my best guess is that this was caused by a recent upgrade of the Azure SDK.