How To Connect And Query Azure SQL Database From Visual Studio Code


In my previous articles, you saw how to create an Azure SQL database and how to query the Database on the Azure portal. Azure SQL Database is a relational Database-as-a-Service which provides high performance, reliable, and secure database that is used to build data-driven applications and websites. In this blog, you will see how to connect and query Azure SQL database from Visual Studio Code. As a prerequisite, make sure you have installed the latest Visual Studio Code and also, you have created the server-level firewall rule to access the database from your machine.

SQL Database Connection Details

Log in to the Azure Portal.

Click SQL Databases -> vijaiDB (which I have created in my previous article). Click Overview and you will see the server name and connection string details which are required to connect to SQL database.


Connect and Query using Visual Studio Code

Open Visual Studio Code.

Click File->New File.


On the right-bottom corner, click Plain Text and select the language mode as SQL.


Install mssql extension. Once installed, click on Reload.


Click F1 and type sqlcon. Click MS SQL: Connect.


Click Create Connection Profile. Enter the server name, database name, authentication type, username, password, and profile name (optional). The profile will be created and connected to Azure SQL database.


Enter the query in the editor. Press Ctrl+Shift+E to retrieve and display the data, as shown below.



Thus, in this article, you saw how to connect and query Azure SQL database from Visual Studio Code.