Daniel Calbimonte

How to simulate the Azure SQL Database storage account behavior using the emulator

April 30, 2018 by

Introduction

When you practice and play with the Azure Storage, you spent money because you need to pay for the service. This obviously provides an incentive to discover a way to emulate the Azure Storage behavior.

In this article, we will use an emulator and learn how it works.

Requirements

  1. First, we will need SQL Server installed
  2. Secondly, we will install SQL Server Management Studio (SSMS)
  3. Finally, you will need administrator privileges to install the software.

Getting Started

Working with the Azure Storage is cheap, but if you are just practicing, you will not want to spend money on it. Here you have the list of prices:

To avoid these costs, we will download the Azure Storage Emulator. You can download the emulator using the following link:

It is also included with the Microsoft Azure SDKs.

The installer is downloaded by default in the following path:

You will find the configuration file there (AzureStorageEmulator.exe.config):

This emulator uses OData to access and connect to the information. The URLs used to access to the blobs, queue messages and tables are the following:

  • Blobs: http://127.0.0.1:10000/
  • Queues: http://127.0.0.1:10001/
  • Tables: http://127.0.0.1:10002/

The account key used by the account name “devstoreaccount1” is in this configuration file and it is the following:

If you need to simulate a proxy, you can add the following line in the configuration file:

To create the database, you can run the following command in the folder where the emulator is installed:

This command will create a database in the localdb. If you do not know what is the localDB and how to use it, we recommend reading our following article:

To start the Azure Storage emulator run the following command in the folder where it is installed:

To stop your emulator, you can use the following command:

To show the status of the emulator you can run the following command:

If it is running the status will be the following: IsRunning: True

To clear all the blob data, use the following command:

You can also clear queue or table data using the following commands:

And

Now, in the SSMS, connect to the database created:

You can also verify the tables created by the Azure Storage Emulator:

To test and verify these tables, we will download the Microsoft Azure Storage Explorer (MASE). You can download the program here:

Install the MASE. MASE can help you to upload and download files to Azure or to the Azure emulator. You can also create Queues and tables.

We will upload some files and create some containers first.

If you have an Azure Account you will need to sign in with your Azure credentials, otherwise, you can omit that part.

In MASE, go to Local and Attached, expand it and to Storage Accounts, Development and Blob Containers:

In the Blob Container can right click and create new blob containers. We will create a blob container named container1. In the container1, you can create new folders upload and download files.

You can verify your accounts in SQL Server. The following query will show the account information including secret keys, queue, blob and table settings:

The table displayed is the following:

You can also check your Blob Container information. Using the BlobContainer table including the last modification date and lease information:

If you query the dbo.BlobContainer table, you will be able to see the container just created:

Other internal tables of the Azure Storage Emulator are the following:

  • Dbo.CommittedBlock contains information about the Azure Account Name, Container name, BlobName and the blocks used. The Azure Storage Accounts.
  • Dbo.CurrentPage will give you page information about the blobs.
  • Dbo.DeletedAccount contains the accounts removed.
  • Dbo.Page handles page information about the blobs contained.

We can also work with Queues in Azure. In MASE, go to Local and Attached, Storage Accounts, Development, Queues.

Right click on Queues and create a new Queue named Queue1:

In the Queue, press Add Message and write a message:

The following query will show the information related to the Queue information:

You will be able to see the queue1 just created:

The dbo.QueueMessage contains the messages created in the queues. In MASE, go to tables and create a new table:

We will create a table named Table1. You can press Add to create a new table and add new properties to the table.

The following query will show the table created:

The Azure local storage is used for development purpose only. It should not be used in production because:

  • It does not offer security. It uses a specific account.
  • It is a simple SQL Server LocalDB instance, and therefore it does not support a heavy workload and it is not designed to have good performance.
  • The limit supported for the blob size is 2 GB.

Note: It is also possible to run the emulator in Docker.

Conclusion

In this article, we learned that we can simulate the Azure Storage Account behavior using the emulator which:

  • works on the command line and you can start or stop it using commands.
  • allows saving the money that Azure may charge if we load data in the Azure Storage Account to test.
  • stores all the information in SQL Server tables using the SQL Server LocalDB.

Also, we learned how to use the AzureStorageEmulator.exe.config

We also reviewed how to create Azure Containers, upload and download files using the emulator. Finally, we created some queues and tables in the Azure emulator and checked where they are stored. This emulator is for Windows, but if you need to run on Linux, there is a version named Azurite. You can download the Linux version here.

See more

Consider these free tools for SQL Server that improve database developer productivity.

References



Daniel Calbimonte

Daniel Calbimonte

Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 13 years of experience working with different databases.

He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs. He is also a writer for SQL Server training material for certification exams.

View all posts by Daniel Calbimonte
Daniel Calbimonte
SQL Azure

About Daniel Calbimonte

Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 13 years of experience working with different databases. He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs. He is also a writer for SQL Server training material for certification exams. View all posts by Daniel Calbimonte

126 Views