Integration of SQL using Azure Portal

|
| By Navneet Kashyap

To integrate SQL into an application using Azure Portal, there are a few steps you need to follow depending on the SQL database service you want to use. The most generally used SQL services on Azure are Azure SQL Database and SQL Server on Azure Virtual Machines (VMs). Below is a step-by-step manual on combining SQL Database and using Azure SQL Database.

SQL Integration on Azure Portal using Azure SQL Database

1. Create an Azure SQL Database

1.1. Login to Azure Portal:

1.2. Create a new SQL Database:

  • From the left-hand navigation pane, click on “Create a resource”.
  • Under Databases, select “SQL Database”.

1.3. Configure SQL Database:

  • Subscription: Select your desired Azure subscription.
  • Resource Group: Create a new resource group or select an existing one.
  • Database Name: Choose a name for your database.
  • Server: Select an existing SQL server or create a new one. If creating a new one, you will need to provide:
    • Server Name: A unique name for the server.
    • Server Admin Login: Choose a username for the SQL admin.
    • Password: Set a strong password.
    • Location: Select the region where your server will be located.

1.4. Select Pricing Tier:

  • Select the appropriate performance and pricing tier (e.g., Basic, Standard, Premium) depending on your needs.

1.5. Review + Create:

  • Review all your settings, and click Create to provision the database.
2. Configure SQL Server Firewall Rules

2.1. Allow Access to the SQL Server:

  • After your SQL database is created, go to the resource you created (SQL Server).
  • Under the Settings section, click on Firewalls and virtual networks.
  • Add your IP address or the range of IP addresses that will be allowed to connect to your SQL server.
3. Connecting to the SQL Database

3.1. Get Connection Strings:

  • From the Azure SQL Database resource page, click on Connection strings under the Settings section.
  • Select your preferred connection method (ADO.NET, JDBC, ODBC, PHP, etc.).
  • Copy the connection string for later use in your application.

3.2. Use the SQL Server Management Studio (SSMS) or other client tools to connect:

  • Open SSMS or your preferred SQL management tool.
  • Enter the server name (e.g., your-server-name.database.windows.net) and use the login credentials created earlier.
  • You can now interact with your SQL database directly or via your application.
4. Integrate with Your Application

4.1. Write Code to Connect to SQL Database:

  • Use the appropriate database driver for your application programming language (e.g., pyodbc for Python, System.Data.SqlClient for C#, or sqlalchemy for Python).
Example code in C#:

using System;
using System.Data.SqlClient;class Program
{
    static void Main()
<bstyle=”color: green;”>    {
        string connectionString = “Server=tcp:your-server-name.database.windows.net,1433;Initial Catalog=your-database-name;Persist Security Info=False;User ID=your-admin-login;Password=your-password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;”;
        

        using (SqlConnection connection = new SqlConnection(connectionString))

        {

            connection.Open();

            SqlCommand com = new SqlCommand(“SELECT * FROM tablename”, connection);

            SqlDataReader reader = com.ExecuteReader();

            

            while (reader.Read())

            {

                Console.WriteLine(reader[0]);

            }

        }

    }

}

4.2. Handle SQL Queries:

  • Once you have established the connection, you can send SQL queries to the database, retrieve results, and use them within your application.
5. Scaling and Monitoring

5.1. Scaling the Database:

  • If you need to scale the database, you can go to the SQL Database resource and select “Configure” under the Settings section to adjust performance tiers (DTUs or vCores).

5.2. Monitor Database Performance:

  • Azure provides built-in monitoring tools such as Azure Monitor and SQL Analytics to monitor the performance, health, and security of your SQL Database. These can be found under the Monitoring section in the SQL Database resource page.
6. Backup and Security

6.1. Automated Backups:

  • Azure SQL Database automatically takes backups. You can configure the retention period and other settings under the Backups section in the SQL Database resource page.

6.2. Data Security:

  • To enhance security, you can enable Transparent Data Encryption (TDE), set up Advanced Threat Protection, and implement Always Encrypted for sensitive data.

6.3. Audit Logs:

  • You can also configure auditing to keep track of all the activities in your SQL Database.
Conclusion

Integrating SQL on Azure Portal using Azure SQL Database is a seamless process that involves creating the database, configuring firewall rules, connecting to it using connection strings, and integrating it into your application. Azure’s scalability, performance monitoring, and security features make it a robust solution for cloud-based SQL integration.

Leave a Reply

Your email address will not be published. Required fields are marked *