Azure Storage Emulator Init - Cannot Create Database :(

Hackered
Thursday, January 21, 2016
by Sean McAlinden

From out of nowhere I was hit with an Azure Storage Emulator 4.2 issue.

The Azure storage emulator wouldn't start and asked me to call AzureStorageEmulator.exe init.

After following the advise to call init, I then received the following error: "Cannot Create Database".

Unforunately the reason for this issue is not displayed so after trying a few potential solutions I found online, I ended up with the following which worked straight away.

Step 1 - Find the database

The Azure Storage Emulator by default uses a local db instance.

I had no idea which instances I may have installed over the last year so I ran the following on the command line:

sqllocaldb i

This command prints out the names of the localDB instances.

In my case I had the following installed:

  • MSSQLLocalDB
  • v11.0

Whilst I knew about v11.0, I had no idea there was another instance called MSSQLLocalDB installed.

In my case this was the culprit - some how the db files for the Azure Storage emulator had gone missing but were still registered in the instance. It now made sense why I couldn't create the database, the instance believed the database already existed.

Step 2: Get rid of the troublesome database

Now that I had found the culprit and I knew I wasn't using the instance for anything else I used the command line to stop and delete it.

Stop:

sqllocaldb stop "MSSQLLocalDB"

Delete:

sqllocaldb delete "MSSQLLocalDB"

Step 3: Run Init on the Azure Storage Emulator

With the rogue database deleted, I went on to run init on the Azure Storage Emulator and all was fine again :)

C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe init

If you have multiple LocalDb instances installed and are not sure which one is the culprit you could just delete them all - the init call on the Azure Storage Emulator will just create the one it needs.

Just remember to back up any data you need before you delete.

S.