Connecting And Working With Azure SQL Database Using Visual Studio 2017

Introduction
 
In this article, I am going to demonstrate how to connect and work with the Azure SQL Database using Visual Studio 2017.
 
Prerequisites 
 
An Azure account. If you don't have a subscription, go to this link to Free Trail!!!
 
Before going to connect to the Azure SQL Database, you should read the article for creating a Database in Azure - Deploying An Azure SQL Database In Microsoft Azure Portal.
 
Follow these steps to connect and work with the SQL Database.
 
Sign into the Azure portal.
 
 

Open the existing database on Azure portal and click "Tools" button on the "Overview" tab at the top of the database blade. 
 
 

In the "Tools" blade, before choosing the Tool, we may configure the Firewall and add our IP Address to the SQL Server; otherwise it will show some error message to you. For that, click "Configure your firewall" link, as shown below.
 
 

Then, click "Add Client IP" option and click "Save" to add your IP to the Azure SQL Database.
 

 
Next, click "Open in Visual Studio" button.
 
 
 
Next , it asks to create the Weblinks to connect our SQL to Visual Studio and then click "Open Link".
 
 
 
Then, Visual Studio opens with "Connect to Server" window already set to connect to the server and database that we selected in the portal. Type your Server Admin password and click "Connect".
 
 
 
After the successful connection, the SQL Server Object Explorer window opens with a connection to our database.
 
 
 
To Run a sample query
 
Now that we're connected to the database, the following steps show how to run a simple query.Right-click the database name and select "New Query".
 
 

In the query window, copy and paste the following code. 
  1. CREATE TABLE student (stuid numeric(15),stuname varchar(50)); 


Click the "Execute" button to run the query. Then, we get the "Command(s) completed successfully" message.

 

Summary
 
I hope that you have learned how to connect and work with the Azure SQL database using Visual Studio.