Controlling the physical storage location of the Azure Storage Emulator

1 minute read

The Azure Storage Emulator is a very convenient tool for working against mocked Azure Storage services – blobs, queues and tables. However, it appears to have no visible means of setting the physical location used for storage, or even determining it. Luckily, both are easily achieve.

Blobs

Blobs are stored on the file system, and that location is very easy to control:

  1. Navigate to _C:UsersAppDataLocalWAStorageEmulator_
  2. Open _WAStorageEmulator..config _with the test editor of your choice
  3. Change the _PageBlobRoot _and _BlockBlobRoot _to the location you desire (the default is something like _C:UsersAppDataLocalWAStorageEmulatorPageBlobRoot_)

Tables and queues

Tables and queues are stored in a SQL server database (LocalDB by default), so in order to set the physical storage location, we simply need to set the physical storage location of the database (mdf file). We’ll use the sqlcmd utility to do that:

  1. Close all programs that may be using the storage emulator database (the storage emulator itself, management studio, visual studio, etc.)
  2. Run sqlcmd -S instancePath
    • By default the storage emulator uses LocalDB, so the above would be sqlcmd -S (localdb)v11.0
    • If you configured a different SQL Server instance you’ll have to use that instead
    • You can always determine the instance path used by the storage emulator by examining the SQLInstance element in the_ __WAStorageEmulator..config_ file mentioned in the Blobs section above
  3. Type the following commands with [enter] after each line:
    1. SELECT name, physical_name AS CurrentLocation, state_desc FROM sys.master_files
    2. Go
  4. You will now see the list of all database files. Pick a file you want to move and note its name and current physical location. For example, suppose you want to move the WAStorageEmulatorDb32 file from its current location to E:StorageEmulatorLocalDBWAStorageEmulatorDb33.mdf
  5. Type the following commands with [enter] after each line:
    1. ALTER DATABASE WAStorageEmulatorDb33 SET OFFLINE with no_wait
    2. Go
  6. Move the mdf file from its current location to E:StorageEmulatorLocalDBWAStorageEmulatorDb33.mdf
  7. Type the following commands with [enter] after each line:
    1. ALTER DATABASE WAStorageEmulatorDb33 MODIFY FILE ( NAME = WAStorageEmulatorDb33, FILENAME = ‘E:StorageEmulatorLocalDBWAStorageEmulatorDb33.mdf’)
    2. ALTER DATABASE WAStorageEmulatorDb33 SET ONLINE
    3. Go
  8. All done. You can verify the result of the move by re-running the commands in step (3) and observing the new file location.

Knowing where the storage emulator stores its data and how to change that location can be useful. For example, if your C: drive is a small SSD, space may be running low. Conversely, your C: drive may be a slow hard disk drive, and you wish to use a faster SSD for storage emulation.

Leave a Comment