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 |
|
[!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.
- An installation of Visual Studio 2019 or later.
- If you don't have an Azure subscription, create a free account before you begin.
- If you don't already have an Azure SQL Database created, visit Quickstart: Create a single database. Look for the option to use your offer to try Azure SQL Database for free (preview).
Sign in to the Azure portal.
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.
-
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.
-
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":::
-
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.
-
In the resource menu, under Settings, select Networking.
-
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":::
-
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":::
-
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.
-
Select Save. A server-level IP firewall rule is created for your current IP address opening port 1433 on the server.
-
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.
- Try Azure SQL Database for free (preview)
- What's new in Azure SQL Database?
- Configure and manage content reference - Azure SQL Database
- Plan and manage costs for Azure SQL Database
Advance to the next tutorial to learn about data migration.
[!div class="nextstepaction"] Migrate SQL Server to Azure SQL Database offline using DMS