Creating Table in Azure Storage Emulator produces HTTP 500 Error
Asked Answered
H

2

8

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?

Haematic answered 7/1, 2016 at 18:10 Comment(2)
Try with UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1; please.Nightjar
Thanks for the idea. However, it didn't change the behavior.Haematic
H
9

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.

Haematic answered 7/1, 2016 at 19:54 Comment(2)
Hi, I recently encountered a problem where GET where working against the emulator table storage but POST and PUT were not. Turns out underlying db was full. The answer above would have solved my issue but I looked into a bit deeper by enabling logs and wrote a blog post about it (if this can help someone): oliviervaillancourt.com/posts/…. ThanksPuzzlement
For future reference, AzureStorageEmulator.exe is installed at C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator by default. From Microsoft DocUntruth
F
0

I think in many cases Johnny's answer will solve the issue.

In my case this also did not work, because AzStorageEmulator did not create the database AzureStorageEmulator510 (database instance (localdb)\MSSQLLocalDB) and also not the tables within.

So I used SSMS to create database AzureStorageEmulator510 from scratch, then I found that an older version AzureStorageEmulator57 was still on my PC, so I attached it (you can find the databases in C:\Users\YOURACCOUNT) - extracted the database structure to a SQL script and ran it for AzureStorageEmulator510.

After that, I started the emulator and created a new blob container using AzStorageExplorer.

The Error 500 seemed to occur because that database (and structure inside) was missing and could not be recreated by the CLI command AzureStorageEmulator.exe init /forceCreate.


Other things you can check (possible issues):

  • It can also be AzStorageEmulator can't access its database. One of the reasons (and how it can be fixed) is described here.

  • After installing a newer version of the instance (localdb)\MSSQLLocalDB, it can be that the related database is not attached. This will result in a strange error like
    Cannot open database "AzureStorageEmulator510" requested by the login. The login failed. Login failed for user 'YOURACCOUNT'.
    If that is the case, you can fix it by simply connecting to localDb via SSMS, then attach the database: Right-click on databases, select Attach... in the context menu, then in the dialog, add the database file (located in C:\Users\YOURACCOUNT).

Falgoust answered 9/11, 2021 at 9:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.