March 14th, 2025

Exploring SQL Server Integration with .NET Aspire: A Collection of Hands-On Samples

Davide Mauri
Principal Product Manager

I’m happy to share a new GitHub repository with developers: azure-sql-db-aspire. This collection of eight hands-on examples demonstrates how to integrate SQL Server and Azure SQL with .NET Aspire, making it easier to build modern, cloud-native applications.

Why .NET Aspire for SQL Server?

.NET Aspire is a new opinionated, cloud-ready stack for .NET applications that simplifies development, observability, and orchestration. SQL Server and Azure SQL are well-supported, allowing developers to quickly integrate databases into their applications while benefiting from Aspire’s service discovery, dependency injection, and seamless deployment.

With Aspire, SQL Server becomes even easier to work with, whether you’re bringing your own instance, deploying it inside an Aspire-managed container, or automating schema deployments.

And when you add Data API Builder (DAB) to the mix, things get even more interesting: You can expose SQL data as REST and GraphQL endpoints in minutes, eliminating the need to manually create a CRUD API.

What’s Inside the Repository?

The repository includes eight examples, each demonstrating a different approach to SQL Server integration with .NET Aspire. Let’s take a closer look at what each one offers.

1. Base Sample

A minimal .NET Aspire application with a simple WebAPI project. This serves as a foundation to build upon, adding SQL Server or Azure SQL integration as needed.

2. Bring-Your-Own-SQL-Server

This builds on the Base Sample, updating the WebAPI to connect to an existing SQL Server instance via a provided connection string. This is the simplest way to integrate SQL Server in Aspire without deploying a new database.

3. Aspire-Hosted SQL Server

In this version, SQL Server is deployed and managed by Aspire, running inside an OCI container. This introduces the Aspire.Hosting.SqlServer library on the server side, while the WebAPI project still fetches the connection string via an Aspire-provided environment variable.

4. Aspire-Hosted SQL Server + DbUp

This expands on the previous example by adding database schema deployment using DbUp.

  • SQL Server is still managed by Aspire.
  • The WebAPI project now gets the connection via Dependency Injection instead of reading from environment variables.
  • Database schema deployment is fully automated via a new Aspire-orchestrated DatabaseDeploy application using the DbUp library.

5. Aspire-Hosted SQL Server + Database Project

Instead of DbUp, this example introduces a declarative database deployment approach using a Database Project. The database schema is now defined and version-controlled in a structured way, and Aspire orchestrates its deployment using CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.

6. Aspire-Hosted SQL Server + EF Core

This version integrates Entity Framework Core (EF Core), allowing the WebAPI project to interact with SQL Server using EF’s DbContext.

  • EF Core’s dependency injection is powered by Aspire.Microsoft.EntityFrameworkCore.SqlServer.
  • Migrations are applied automatically using an Aspire-orchestrated Worker Service.

Note: For simplicity, the EF Core models and migrations are defined inside the WebAPI project, though best practices would involve using a separate project.

7. Aspire-Hosted SQL Server + DbUp + Data API Builder

This sample builds upon the previous DbUp sample but removes the WebAPI project entirely—because now, Data API Builder (DAB) handles everything!

  • DAB exposes the database as REST and GraphQL APIs, eliminating the need for manual API development.
  • DAB is fully orchestrated by Aspire, using CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder.

Perfect for rapid backend development when you need to quickly expose data via APIs.

8. End-To-End Jamstack “ToDo List”

A full-stack example that combines:

  • Vue.js frontend
  • Data API Builder (DAB) backend
  • SQL Server database deployed via a Database Project
  • Node.js application (TodoApp.Frontend), orchestrated with Aspire’s CommunityToolkit.Aspire.Hosting.NodeJS.Extensions

This demonstrates how you can build modern web apps with an entirely Aspire-managed backend powered by SQL Server + DAB.

Why This Matters

If you’re building cloud-native applications with SQL Server and .NET Aspire, this repository provides practical, real-world samples to get started quickly.

Key benefits of these approaches:

  • Faster integration of SQL Server and Azure SQL with .NET Aspire
  • Multiple options: BYO SQL Server, Aspire-hosted containers, or declarative database projects
  • Automated database provisioning with DbUp, Database Projects, or EF Core migrations
  • Zero-code backends with Data API Builder (DAB), enabling instant REST and GraphQL APIs
  • Full-stack orchestration with Aspire for databases, APIs, and frontend applications

Get Started 🚀

Explore the repository here: azure-sql-db-aspire

Try out the samples, see what works for your needs, and feel free to contribute or provide feedback!

Author

Davide Mauri
Principal Product Manager

Principal Product Manager in Azure SQL, with a career in IT spanning since 1997, earning the prestigious Data Platform MVP status for 12 consecutive years. Currently, he serves as the Principal Product Manager for Azure SQL Database, focusing on developers and AI.

0 comments