How to connect to Azure SQL Database (Part 1)

The shift from on-premises services to cloud services has become a growing trend due to its cost-effectiveness, scalability, and speed. Additionally, the cloud provider is responsible for platform maintenance. This means users can focus on their applications without worrying about availability, security, updates, patches or backups.

Azure SQL is one of the most popular cloud platforms - relational database as a service, the SQL Server engine hosted in the Azure cloud. It allows any application developed using SQL Server to be easily moved to the cloud and work with them using familiar tools and resources.

The Azure portal has its own query editor, but if you want to apply other tools, such as SQL Server Management Studio (SSMS), you can easily connect to Azure SQL Database using this or other compatible applications. This article explores how to connect to Azure SQL Database using a local application.

  • Before you begin: Azure connection credentials and firewall
    • How to retrieve Azure connection credentials
    • How to configure server firewall
  • Connect to Azure using SQL Server Management Studio
  • Connect to Azure using dbForge Studio for SQL Server
    • Connect using Azure Active Directory authentication
  • Connect to Azure using Visual Studio
  • Connect to Azure using Power BI
  • Connect to Azure using PowerShell
  • in conclusion

dbForge Studio for MySQL 下载(qun:765665608)icon-default.png?t=N7T8https://www.evget.com/product/1708/download

Before you begin: Azure connection credentials and firewall

To connect to Azure from an on-premises application, you need a valid Azure subscription and a database in the cloud. You can then get the login credentials to use when connecting to Azure from your local application.

How to retrieve Azure connection credentials

If you have never used Azure SQL, you need to first create afree account.

Azure Database provides a test database, Wide World Importers, that you can use as an example. However, first, you need to create a database to deploy the sample database and access its schema and data. Microsoft provides detailed instructions, so this task should take a few minutes.

Azure Database is a paid service, but it offers a 30-day free trial so you can try out the feature and properly evaluate it using this test database and other databases you want to use.

After creating an empty database and deploying the test Wide World Importers database, you can get it in your Azure account as mySampleDatabase.

The username and password set during database creation are the login details required to connect to Azure SQL Database from other applications. In the Overview section, you will see the fully qualified server name next to Server Name at the top:

These details allow you to connect to Azure SQL Database from other applications. However, there is one mandatory step left - you need to configure the firewall.

How to configure server firewall

By default, connections to Azure SQL Database from outside the Azure environment are blocked. Azure has server-level firewalls in place for these databases. Therefore, to allow external access, you must set up firewall rules specifying the allowed IP addresses or IP address ranges.

In your Azure account, navigate to the SQL Database section and select mySampleDatabase.

Azure SQL

Click Set Server Firewall. By default, the platform displays network and existing firewall rules.

Click Add your client IP to configure the new firewall rule, and save the changes.

This rule ensures that port 1433 (which the server listens on) is open to the specified IP address. Additionally, you can configure any firewall rules for your environment by clicking Add Firewall Rule.

Now, let's review how to connect to Azure SQL Database from local tools.

Connect to Azure using SQL Server Management Studio

SQL Server Management Studio is the default integrated development environment for SQL Server databases. If you are an Azure SQL user, there is no reason to reject SSMS. You can use it to connect to a SQL database in Azure, query the database, retrieve data, and perform other necessary operations.

Let’s examine how to connect to an Azure Database from SQL Management Studio. The process is generally similar to connecting to other local databases, but there are some peculiarities that you should be aware of.

Open SSMS and start a new connection. Enter the following details:

Server type: Database engine
name of server: Required fully qualified server name
verify: SQL Server Authentication
Log in: The username you set when creating the database
password: your password

Then click Options > Connection Properties. You need to define the database to connect to:

Click Browse and select mySampleDatabase from the drop-down menu:

Click Connect. Afterwards, SSMS connects to Azure SQL and displays the database in the Object Explorer pane. You can query this database in the same way as other databases in SSMS. ,

Important: Azure SQL Database does not support the USE statement. In our scenario we are using only one SQL database in the cloud, but if you have more databases and want to switch between them in SSMS, you will need to establish a new connection for the new database.

Connect to Azure using dbForge Studio for SQL Server

Many SQL Server experts usedbForge Studio for SQL Server as an alternative to SSMS. Studio is a versatile IDE that includes features and options not available in default SSMS. Additionally, Studio is fully compatible with Azure, so you can apply it to efficiently use Azure SQL Database.

To connect to Azure SQL Database, make a new connection in Studio and enter the server name and credentials. Click Connect.

Once the connection is established, you will see mySampleDatabase in the Object Explorer menu and be able to query the database directly.

Connect using Azure Active Directory authentication

dbForge Studio for SQL Server also supports connecting to Azure Databases via Azure Active Directory authentication, granting more secure access. Users can use the following authentication types:

  • Azure Active Directory – Common features with MFA support
  • Azure Active Directory – Password
  • Azure Active Directory – Integration

The default option is Universal with MFA support. To use it, you first need to register dbForge Studio for SQL Server as an Azure Active Directory application and obtain the application ID that will be generated during the registration process. Afterwards, you will be able to connect to Azure Database through Azure Active Directory Universal with MFA-enabled authentication.

Start a new connection in Studio: Database > New Connection > Select Azure Active Directory – Universal with MFA support as the authentication type.

Enter the credential details:

Server: URL of the Azure SQL Server instance.
Username: Azure Active Directory user with Azure SQL Database permissions.
Select Use common MFA options and click Change common options.

In the new window, enter the Application ID and redirect URL generated during registration of dbForge Studio for SQL Server:

Note: If you want to insert an alternate application ID, select the Override MFA for this connection option in the previous step and enter the application ID and redirect URL.

Click OK to save the details, then click Connect to establish the connection.

You will be prompted to log in to your account. In the login window that appears, enter the credentials for your Azure Active Directory account. After successfully logging in, you will be able to access the database in dbForge Studio for SQL Server.

Studio also supports Azure Active Directory – Password and Azure Active Directory – Integrated authentication types, you can choose one of these types and follow the detailed instructions to establish a connection.

Due to the length of this article, please continue browsing and jump to the next chapter,"How to connect to Azure SQL Database (Part 2)"You are also welcome to communicate in the comments~~~

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/135012396