29
votes

I am having an issue with Azure Storage Emulator. I tried to re-initialise the database and got the error below.

This was after installing Visual Studio 2019 Preview but this may just be a co-incidence. I tried for an hour or so to get it running and then gave up and just reset my machine with the "keep my files" option, re-installed Visual Studio 2017 and the Azure Tools but still see the same problem.

I know a reset sounds a bit drastic but VS 2019 broke my Azure Functions in VS2017, they would not launch so I wanted a clean install.

If I manually create the DB with sqllocaldb create (version 13.1.4001.0), the DB gets created fine but the init still fails with the same message.

Any ideas?

C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>AzureStorageEmulator.exe init Windows Azure Storage Emulator 5.7.0.0 command line tool Found SQL Instance (localdb)\MSSQLLocalDB. Creating database AzureStorageEmulatorDb57 on SQL instance '(localdb)\MSSQLLocalDB'. Cannot create database 'AzureStorageEmulatorDb57' : The database 'AzureStorageEmulatorDb57' does not exist. Supply a valid database name. To see available databases, use sys.databases.. One or more initialization actions have failed. Resolve these errors before attempting to run the storage emulator again. Error: Cannot create database 'AzureStorageEmulatorDb57' : The database 'AzureStorageEmulatorDb57' does not exist. Supply a valid database name. To see available databases, use sys.databases..

15
Have you tried to install the latest v5.8 emulator?Jerry Liu
Yes, the 5.8 installer goes through fine but the problem remains.Murray Foxcroft

15 Answers

35
votes

After resetting my machine (and keeping files), I ran into this issue. For me, I was unable to run an Azure function in Visual Studio 2019 due to an error around being unable to start the emulator.

It looks like I had the same permissions issues as (I presume) my new account after reset, did not have permission to touch the DB.

I resolved this by:

  1. Deleting the Azure Storage Emulator DB file: %USERPROFILE%/AzureStorageEmulatorDb[number].mdf
  2. Then running AzureStorageEmulator.exe start with admin rights

I was then able to run the Azure Function without issue.

28
votes
  1. Stop the Azure Emulator if it is running.
  2. Open SSMS and connect to your (localdb) instance.
  3. Manually create the "AzureStorageEmulatorDb57".
  4. Open a command prompt as Administrator.
  5. Run the "AzureStorageEmulator.exe init".
  6. Run your VS project.
24
votes

I was running into this same issue after installing LocalDb for SQL Server 2017. These steps helped me to resolve the problem I was facing:

  • Open a command line in C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
  • Run AzureStorageEmulator.exe init /forceCreate
  • From checking my error logs (located at %USERPROFILE%\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB), I saw

2018-12-21 15:41:13.47 spid65 CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Users{username}AzureStorageEmulatorDb59.mdf'.

  • This error lead me to the following post: https://dba.stackexchange.com/questions/191393/localdb-v14-creates-wrong-path-for-mdf-files
  • From reading answers there, I gathered that this is a bug in SQL Server 2017. Without having access to the patch, the solution that worked for me was granting Everyone access to modify C:\Users. This was only an issue on my development laptop, so I could afford to make that security change
  • or as commented by Andrii install CU13 HotFix for SQL Server 2017. After that AzureStorageEmulatorDb<xxx>.mdf will be created you your user directory as it should.
15
votes

I had this problem and I don't know why an AzureStorageEmulatorDb57_log.ldf was still present in my %USERPROFILE% directory when I deleted my MSSQLLocalDB instance, but after dropping that file the problem went away.

3
votes

I came across this issue where I had changed the userlogin to my machine. I have created the database from my previous useraccount. I have copied the database files to the new user account but it gave me this error. It seems to be a permission issue.

You need to find the saved location of the mdf and ldf file of this database. In my case it was stored in 'C:\Users\yourUserName'

Simply delete these files and run AzureStorageEmulator.exe init again and it will create the new mdf and ldf files for you.

2
votes

After manually upgrading my MSSQL 2016 LocalDB to MSSQL 2019 following these instructions, I got the error mentioned as I was unaware that the Azure Storage Emulator uses LocalDB internally.

To fix it, I simply had to manually re-attach the database located in %UserProfile% with the following SQL command:

CREATE DATABASE [AzureStorageEmulatorDb510]
    ON (FILENAME = 'C:\Users\<username>\AzureStorageEmulatorDb510.mdf'),   
    (FILENAME = 'C:\Users\<username>\AzureStorageEmulatorDb510_log.ldf')   
    FOR ATTACH;
1
votes

Worked for me:

  1. Delete any storage/sql database related to azure emulator
  2. run this command on StorageEmulator path:

AzureStorageEmulator.exe init /server .

(Or your SQL instance, Mine was ".")

0
votes

Check you had install Azure SDK with Visual Studio, if you did't you can add the feature

Error

No Error

0
votes

You can locate the mdf and ldf files in your userprofile directory. Just stop the emulator and copy those files to some other place and delete it from userprofile directory. Then run the emulator again and it's going to create new mdf and ldf files. Then stop the emulator and copy the old files back and restart the emulator. This way you won't loose any data.

0
votes

I will help you with this. First of all create a sql server local db. Then go to storage emulator folder _-The Storage Emulator is installed by default to C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator.

Then run this AzureStorageEmulator.exe init /server

docs: AzureStorageEmulator.exe init /server localhost\SQLEXPRESS01

0
votes

Open SSMS and connect to your (localdb) instance. Manually create the "AzureStorageEmulatorDb...".

0
votes

To add yet another answer, I did not have the any MDF or LDF files. Instead, I only had a config file at %USERPROFILE%\AppData\Local\AzureStorageEmulator\AzureStorageEmulator.5.10.config. I also could not connect to my local (localdb) instance with SSMS.

I changed the SQLInstance value in that config file to be localhost rather than (localdb)\MSSQLLocalDB, and it started working.

0
votes

You should have an app called Microsoft Azure Storage Emulator.

enter image description here

Start this application.

If the application indicates that it is running run AzureStorageEmulator.exe stop first otherwise run AzureStorageEmulator.exe Start directly. Should create your database automatically, at least it did for me.

enter image description here

https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator

-1
votes

I initialized the db instance and succeed, bu my SQLServer is 2017.

Then I search the solution and the doc said delete the trouble database will solve the problem. Maybe you can try it follow the steps in the doc.

If you still have questions, please let me know.

-1
votes

This solution is not recommended in generally, but you can try it. I think AzureStorageEmulator by somehow can not full access the localDB whitch setup in directory has limited the permission.

  1. You can go to folder propertiy > sercurity > edit to full permission ( with me directory is user > Appdata).
  2. Then restart the emulator cmd restart the azure emulator.

Now it worked. You must consider it's unsercurity later on.