Skip to content

Latest commit

 

History

History
95 lines (64 loc) · 5.78 KB

design-first-database-csharp-tutorial.md

File metadata and controls

95 lines (64 loc) · 5.78 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic ms.custom
Design your first relational database C#
Learn to design your first relational database in Azure SQL Database with C# using ADO.NET.
WilliamDAssafMSFT
wiassaf
mathoma
06/25/2024
sql-database
development
tutorial
sqldbrb=1
devx-track-csharp

Tutorial: Design a relational database in Azure SQL Database C# and ADO.NET

[!INCLUDE appliesto-sqldb]

Azure SQL Database is a relational database-as-a-service (DBaaS) in the Microsoft Cloud (Azure). In this tutorial, you learn how to use the Azure portal and ADO.NET with Visual Studio to:

[!div class="checklist"]

  • Create a database using the Azure portal
  • Set up a server-level IP firewall rule using the Azure portal
  • Connect to the database with ADO.NET and Visual Studio
  • Create tables with ADO.NET
  • Insert, update, and delete data with ADO.NET
  • Query data ADO.NET

Tip

This free Learn module shows you how to Develop and configure an ASP.NET application that queries an Azure SQL Database, including the creation of a simple database.

Prerequisites

Sign in to the Azure portal

Sign in to the Azure portal.

Create a server-level IP firewall rule

SQL Database creates an IP firewall at the server-level. This firewall prevents external applications and tools from connecting to the server and any databases on the server unless a firewall rule allows their IP through the firewall. To enable external connectivity to your database, you must first add an IP firewall rule for your IP address (or IP address range). Follow these steps to create a server-level IP firewall rule.

Important

SQL Database communicates over port 1433. If you are trying to connect to this service from within a corporate network, outbound traffic over port 1433 might not be allowed by your network's firewall. If so, you cannot connect to your database unless your administrator opens port 1433.

  1. After the deployment is complete, select SQL databases from the left-hand menu and then select yourDatabase on the SQL databases page. The overview page for your database opens, showing you the fully qualified Server name (such as yourserver.database.windows.net) and provides options for further configuration.

  2. Copy this fully qualified server name for use to connect to your server and databases from SQL Server Management Studio.

    :::image type="content" source="media/design-first-database-csharp-tutorial/server-name.png" alt-text="Screenshot of the Azure portal, database overview page, with the server name highlighted." lightbox="media/design-first-database-csharp-tutorial/server-name.png":::

  3. In the Azure portal, navigate to the logical SQL server for your Azure SQL Database. The easiest way is to select the Server name value on the SQL database page.

  4. In the resource menu, under Settings, select Networking.

  5. Choose the Public Access tab, and then select Selected networks under Public network access.

    :::image type="content" source="media/design-first-database-csharp-tutorial/server-firewall-rule.png" alt-text="Screenshot of the Azure portal, Networking page, showing that public network access is enabled." lightbox="media/design-first-database-csharp-tutorial/server-firewall-rule.png":::

  6. Scroll down to the Firewall rules section.

    :::image type="content" source="media/design-first-database-csharp-tutorial/firewall-ip-address.png" alt-text="Screenshot of the Azure portal, Networking page, Firewall rules section." lightbox="media/design-first-database-csharp-tutorial/firewall-ip-address.png":::

  7. Select Add your client IPv4 address to add your current IP address to a new IP firewall rule. An IP firewall rule can open port 1433 for a single IP address or a range of IP addresses.

  8. Select Save. A server-level IP firewall rule is created for your current IP address opening port 1433 on the server.

  9. Select OK and then close the Firewall settings page.

    Your IP address can now pass through the IP firewall. You can now connect to your database using SQL Server Management Studio or another tool of your choice. Be sure to use the server admin account you created previously.

Important

By default, access through the SQL Database IP firewall is enabled for all Azure services. Select OFF on this page to disable access for all Azure services.

[!INCLUDE sql-database-csharp-adonet-create-query-2]

Tip

To learn more about writing SQL queries, visit Tutorial: Write Transact-SQL statements.

Related content

Next step

Advance to the next tutorial to learn about data migration.

[!div class="nextstepaction"] Migrate SQL Server to Azure SQL Database offline using DMS