Azure Storage Emulator fails to init with "The database 'AzureStorageEmulatorDb57' does not exist"
Asked Answered
K

17

40

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..

Kanaka answered 7/12, 2018 at 16:51 Comment(2)
Have you tried to install the latest v5.8 emulator?Stomatic
Yes, the 5.8 installer goes through fine but the problem remains.Kanaka
E
61

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.

Epanorthosis answered 2/9, 2019 at 12:42 Comment(4)
Thank you it worked, I deleted the .mdf file and rerun storage emulator START command. doneDicot
Yeah! This works for me, simply delete the mdf files and then run the ´init´ command again. ThanksMahla
Thanks! That helped me also. I migrated to a new pc and accidentally copied this mdf file to the new pc so it prevented azure emulator from creating the db. Deleted it and it worked.Foible
This worked for me, I have to vote this solution upSynchronism
M
28
  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.
Mord answered 28/12, 2018 at 15:49 Comment(0)
C
25

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.
Crispin answered 21/12, 2018 at 22:8 Comment(4)
Indeed this was the issue. I installed CU13 HotFix for SQL Server 2017 and it works now.Semidiurnal
Granting Everyone access to modify C:\Users solved my problem. Thank you.Unpopular
@Andrii this is much better solution (more secure), to problem described by this answer, big thanks. I've added that to aleroy answer.Indict
this sequence work for me , stop->clear -> init-> start github.com/Azure/azure-storage-net/issues/…Circumnavigate
A
16

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.

Agrimony answered 2/3, 2019 at 12:6 Comment(1)
this worked for me but before doing this, i also installed SQL Express, so not sure which one fixed the issueCaudate
B
3

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.

Blunder answered 2/4, 2019 at 8:55 Comment(1)
This resolved it for me too. Had the same error with both 2016 and 2019, and when I attempted to manually create the database using SSMS I finally got a useful error message (unable to create database due to file already existing) that pointed me to this solution. It's a shame the storage emulator was hiding that error message!Heraldry
D
3

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;
Dispassionate answered 13/1, 2020 at 10:6 Comment(0)
L
2

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 ".")

Lianaliane answered 22/11, 2020 at 15:9 Comment(0)
J
1

This would probably not fit in the general case but for me I had to go into my Task Manager and stop the Azurite process. Then I went back into the directory and typed the start command:
%\Azure\Storage Emulator\ AzureStorageEmulator.exe start

this solved it for my case and wanted to share in case.

Jackquelinejackrabbit answered 29/8, 2023 at 21:42 Comment(0)
W
0

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

Error

No Error

Wace answered 28/1, 2020 at 16:12 Comment(0)
B
0

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.

Blunder answered 4/6, 2020 at 12:13 Comment(0)
K
0

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

Kessia answered 14/10, 2020 at 17:33 Comment(0)
S
0

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

Suber answered 10/2, 2021 at 23:49 Comment(0)
A
0

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.

Anther answered 2/6, 2021 at 15:45 Comment(0)
F
0

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://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator

Fourdimensional answered 16/6, 2021 at 14:43 Comment(0)
C
0

This seems to be because the mdf file already exists but LocalDB doesn't have it attached. You can delete and recreate as others have mentioned, but in my case I was able to just re-attach it and it worked fine.

  • Open SSMS to (localdb)\mssqllocaldb
  • Right click Databases
  • Choose Attach
  • Click Add
  • Select the existing MDF file (mine was in my user profile and named AzureStorageEmulatorDb510.mdf)
  • Click Ok

Then try running the emulator again.

Canasta answered 8/6, 2022 at 17:29 Comment(0)
F
-1

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.

Frustrated answered 12/12, 2018 at 9:18 Comment(1)
I did try that and more. A fresh rebuild of my laptop solved it.Kanaka
E
-1

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.

Equivocal answered 20/1, 2019 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.