You are on page 1of 22

How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Search

How to connect an Azure database to third-


party services
Anthony Schroth (DMObjects) · Follow
7 min read · Sep 12, 2019

Listen Share

Software-as-a-Service (SaaS) encircles perhaps the most comprehensive set of


solutions for software development. Databases, scheduled jobs, firewalls,
DevOps, you name it. The area of SaaS is teeming with new and exciting ways to
work and mainstream the delivery of our technological solutions here at
DMObjects Web and Design, which is why I want to share a few tips to start using
these types of services.

One of the most powerful cloud SaaS suites at the moment is Microsoft Azure. It
provides:

• Databases

• Both Linux and Windows virtual machines

• Kubernetes

• Mobile apps

• VPNs

• File storage

• Machine learning

• and many more.

1 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

It’s incredible, actually. I could go on all day about the plethora of things that
Microsoft knows that are of great value for the future of software development.
But, because attention span is limited I’ll go ahead and teach you how to connect
an Azure database to ASP.NET, Python, Power BI, and SQL Server Management
Studio.

We’ll go from creating a free trial account on Azure all the way towards
connecting our database and performing a query.

Azure is Microsoft’s take on cloud computing

Creating a free Microsoft Azure account


First, let’s create a free Microsoft Azure account. You can do so here. You will
need a valid credit card (which will not be charged for this tutorial) and a valid
telephone number to verify your identity by SMS.

Free trial accounts have their limitations, mainly:

• 12 months of access

• 30 days of service

• $200 credit

Keep in mind that all your testing should take place within the 30-day period.
After that, your data will remain read-only and you’ll need to upgrade to keep on
using Azure services as a whole. Regarding the $200 credit, that gets depleted as

2 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

your account’s performance requirements increase. For example, whenever you


run jobs in your virtual machines, a certain amount will be deducted from your
credit.

After creating your account, you should be greeted by this screen:

Now, head to https://portal.azure.com/. You will be offered a tour of the suite; you
can do this later.

Creating the database


Click “SQL Databases” and then select “Add”

3 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Creating a new SQL Server database

Create a new resource group, add a database name and create a new server. Take
note of the information provided, you’ll need it later!

4 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

You will be asked to review the creation of the database, alongside the estimated
cost per month of using it.

Finish the process and wait for the database to deploy.

Now, select “SQL Databases” on the left-side panel, choose your newly-created
database server and click “Set server firewall.”

Get your IP address by searching “what’s my ip” on Google and take note of it.

5 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Then, create select “ON” on “Allow access to Azure services” and create a new
rule that includes your IP address.

Save your changes and once again, select “SQL Databases” and choose your new
server. Now, click “Connection strings” and take note of the connection strings.
Different services will require different connection strings.

6 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Go back to “SQL Databases” and now select “Query Editor.” Put your admin
credentials and we will see the SQL Query editor. Let’s create a test table called
“Person” and insert “Will Williamson” as our test instance. Note that the Query
Editor allows us to export data as .csv and .xml, how cool is that?

We’re ready to start connecting to our database!

Connecting to Azure SQL Database with ASP.NET


Open up Visual Studio and create a new ASP.Net Web Application (.NET
Framework)

7 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

First, let’s connect our database to Visual Studio, so we can make tests in the
future without having to mess around with our source code.

Click “Tools” and then “Connect to Database…”

8 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Select “Microsoft SQL Server” and click “Continue”

9 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Now, we must enter the credentials that we noted earlier. Keep in mind that there
are three main components to this process: Server, database and username.

10 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Now that Visual Studio is connected, the next step is to actually connect out
ASP.NET app to the database. To do that, we head down to the Web.config file and
we create a new block called “connectionStrings”. Inside, we must add the
ADO.NET connection string, alongside our database credentials.

11 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

We can test the connection by creating a SQL Query file and running it directly
from Visual Studio.

Connecting to Azure SQL Database with Python


I will assume that you are acquainted with developing in Python in your
environment of choice. If not, you should read up on setting up virtual
environments and installing packages.

12 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

First, install PyODBC, which is the Open Database Controller for Python, which
allows it to connect to SQL Server instances. You can do so by opening a
command prompt and entering:

>pip install pyodbc

After successfully installing the package, open your IDE of choice and write the
following script:

import pyodbc

AZURE_STRING = <Insert your Azure SQL Server ODBC connection string here, with
its required credentials>

cnxn = pyodbc.connect(AZURE_STRING)

cursor = cnxn.cursor()

cursor.execute(“SELECT * FROM Person”)

row = cursor.fetchone()

print(row)

Now, run the script and you should see our test instance appear onscreen.

Connecting to Azure SQL Database with Power BI


Open up Power BI Desktop and create a new file by clicking the “File” menu and
selecting “New.” Click “Get data.”

You will be presented with all the compatible data sources for Power BI. Scroll
down and select Azure SQL Database.

Now enter the name of the server and the name of the database.

13 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Note that there are two options under “Data Connectivity mode”:

• Import: This imports the result of queries from the database. It is useful if the
Power BI visualizations do not need to be updated all the time.

• DirectQuery: This performs live queries to the database, which is more


intensive on processing power but allows for live updates of your data.

After clicking “OK”, you will be prompted to insert your credentials. Enter the
same credentials you used in the earlier steps.

14 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Click “Connect” and wait for the authentication process.

Eventually, you should see our test instance on the screen!

Connecting to Azure SQL Database with SQL Server Management


Studio
Connecting to your Azure SQL Database with SQL Server Management Studio
(SSMS) is very easy, too. You just open up SSMS and enter the server name and
your admin credentials. Then, hit “Connect.”

15 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

SSMS has the issue that, when dealing with online services, it may be a tad too
slow. It is a fully-equipped suite for interacting with your SQL Server databases,
so it must get a lot of data from the current instance to work correctly.

When developing, it is always better to work locally, and after you’ve done your
tests, then it is advised to pass on to a remote test environment. This is because
query latency is oftentimes ignored, mainly because it is pretty much invisible in
local testing environments. Take your previsions!

After the connection has been established, you can create a “New Query” and see
our neat little test instance.

16 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Conclusion
I hope that this little guide has been of use. Cloud-based computing is sure to
provide many solutions to software developers and in the case of Microsoft
Azure, opening a free trial account to test its services is just so easy. It is hard to
resist the wide variety of tools they offer.

For web and app design solutions feel free to visit my company’s website at
https://www.dmobjects.ca.

We offer competitive prices and we specialize in working with startups and small
businesses. Our services include web hosting, corporate emails, e-commerce
platforms and much more.

Sql Server Azure Python SaaS

17 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Follow

Written by Anthony Schroth (DMObjects)


0 Followers

We specialize in delivering the finest web design and custom application development for businesses.

Recommended from Medium

18 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Aasim Afridi

Building Your First Azure DevOps CI CD Pipeline: A Step-by-Step Guide


What and Why Azure Pipelines?

8 min read · Sep 4, 2023

73 1

SLIIT Data Science Student Community

Fetch data from a REST API Source using Azure Functions


Introduction

5 min read · Aug 17, 2023

67

Lists

Coding & Development


11 stories · 427 saves

Predictive Modeling w/ Python


20 stories · 868 saves

Practical Guides to Machine Learning


10 stories · 1011 saves

ChatGPT
21 stories · 439 saves

19 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Beyza Ozgur

Introduction to Azure Functions


In this post, we will explore the concept of Azure Functions and highlight key scenarios
where they can be effectively used.

4 min read · Jan 14

23

20 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Lennart Svensson

Planning the architecture of your web application


Once you are set up with an Azure account and a subscription, you are ready to start
building and deploying your web application. However…

4 min read · Aug 10, 2023

11

Chirag Darji

Using Azure Key Vault Secrets with .NET Core 7 Web API
Topics covered in this article are…

9 min read · Sep 28, 2023

21 of 22 2/6/2024, 12:52 PM
How to connect an Azure database to third-party services |... https://medium.com/@dmobjects/how-to-connect-an-azu...

Usamashafique

90+ Best DevOps Tools [Updated for 2024]


As DevOps engineers, it is very important to know about the DevOps tools landscape. Each
project has different requirements and the right…

8 min read · Jan 26

338 3

See more recommendations

22 of 22 2/6/2024, 12:52 PM

You might also like