Azure SQL Database emulator in VS code

Nov 18, 2022 2:55 PM

Personal blog
Microsoft
Azure
SQL Database
VS Code

Getting started

In the past people often used a SQL Server Developer (or Express) version for their local development environment and while this practise continued, it also common to develop directly on a development environment within your DTAP.

Both options come with their own flaws, as for a local SQL Server doesn’t represent an Azure SQL Database correctly and developing directly on a Development environment would often cause issues with continuity for other developers working on the Database.

For this a solution has created, the Azure SQL Database emulator! The emulator allows you to locally develop your database needs for Azure SQL in both VS code and Azure Data Studio. But that is not all! It also allows you to integrate it within your CI/CD pipelines for testing and validation purposes, I might touch that subject in a later blog, as for now I will focus on how to setup the Azure SQL Database emulator within VS Code.

Before we begin, there are some requirements that need to be met, in this case the following will need to be installed:

and with everything installed, let’s have a look on how to work with the Emulator!

Database project in VS code

For a New Project go to the Database Projects tab, click on Create new, select Azure SQL Database and enter a proper project name. You will be asked to choose a directory for the project's folder, .sqlproj file and everything else.

When the new project created it can be opened/ will be visible in the Database Projects tab. If you right-click on the project name, click on Add Table to create some new tables to browser later on.

NOTE: If you already have a Database Project, click on Open Existing and navigate to the directory in which the .sqlproj is located.

Build and deploy to the Emulator

First the Database project needs to be build, this can simply be done by right clicking on the .sqlproj and choose Build and wait till the build is completed.

To deploy your database project to the Emulator, go to the Projects tab, and right-click on the .sqlproj and choose Publish.

You will be prompted with multiple options, choose the Publish to new Azure SQL Database emulator. You will be asked to for a port, admin password, full or lite emulation, if you agree to the terms, the version like latest, a profile and finally the Database itself.

When the publishing is complete the Emulated container will appear in the Docker Desktop application and you will automatically connect to it!

What's next?

It was nice to switch up the subject once in a while, but next week I will dive into converting Logic Apps from the Consumption to Standard plan, till next week!