Connecting an Azure SQL Database with Visual Studio Code

Introduction

 
In this article, you will learn about how to connect an Azure SQL database with Visual Studio code. Visual studio code is one of the most popular IDEs for programming and development in software fields. In case web developers developing web applications and Azure or other databases are a backend of web applications. During development time developers can test some DML operations in the database. Handling multiple tools is difficult in some places. So, we are going to connect the Azure SQL database in VS code.
 
Prerequisites
  • Azure cloud account
  • Visual studio code IDE installed (Download link)
  • Edge (or) Other browsers
  • Stable Internet Connection
  • Minimum knowledge in Database
  • Azure SQL server & database
Step 1
 
Login to the Azure portal.
 
Step 2
 
Go to your database Dashboard and then click the “Set server firewall” option at the top of the dashboard.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 3
 
In the firewall settings page, click the “Add client IP” button, our client IP added to the rule list. Next, click the “Save” button to save our client IP.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 4
 
Open your visual studio code IDE, first we install SQL tool in visual studio code. Click the “Extension” icon from the left sidebar and then search “SQL Tools' ' in the extension search bar. SQL tool is available in extension and then click the install button and wait a few minutes to complete the installation.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 5
 
After installation is completed, click the database icon and then click the “SQL Tools” icon and then click the “Add connection” icon at the connection area.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 6
 
Next, select “My SQL Server” on the connection assistance page.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 7
 
The connection settings page gives a “Connection name” and “Connection Method” to create a new connection.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 8
 
Next, we can get a connection string from Azure. So, go to the Azure SQL database dashboard and then select “Connection strings” from the left pane.
 
Copy the connection string from the “ADO.NET” tab.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 9
 
Next, come to the visual studio code, now paste the copied connection string and set the timeout. In the connection string, we can give our SQL server password. (Password is given during the server creation).
 
All of the fields are completed, click the “Test connection” button.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 10
 
Our connection is successful, click the “Save connection” button.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 11
 
In the connection review page, our connection information is displayed on that page. Click the “Connect now” button.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Step 12
 
Our database connection is established with a visual studio. On the left side pane, our database information is displayed, including the database name, table name and column name.
 
Connecting Azure SQL Database In Visual Studio Code 
 

Summary

 
Execute the simple SELECT query in vs code to fetch all data from selected tables.
 
Connecting Azure SQL Database In Visual Studio Code 
 
Finally, we have successfully connected our Azure SQL database with our Visual Studio code.