{"id":4339,"date":"2025-03-14T08:06:47","date_gmt":"2025-03-14T15:06:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=4339"},"modified":"2026-02-23T11:37:18","modified_gmt":"2026-02-23T19:37:18","slug":"exploring-sql-server-integration-with-net-aspire-a-collection-of-hands-on-samples","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/exploring-sql-server-integration-with-net-aspire-a-collection-of-hands-on-samples\/","title":{"rendered":"Exploring SQL Server Integration with .NET Aspire: A Collection of Hands-On Samples"},"content":{"rendered":"<p>I&#8217;m happy to share a new GitHub repository with developers: <a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-aspire\">azure-sql-db-aspire<\/a>. 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.<\/p>\n<h2>Why .NET Aspire for SQL Server?<\/h2>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/aspire\/overview\">.NET Aspire<\/a> is a new <strong>opinionated, cloud-ready<\/strong> 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\u2019s service discovery, dependency injection, and seamless deployment.<\/p>\n<p>With <strong>Aspire<\/strong>, SQL Server becomes even easier to work with, whether you&#8217;re bringing your own instance, deploying it inside an Aspire-managed container, or automating schema deployments.<\/p>\n<p>And when you add <strong>Data API Builder (DAB)<\/strong> 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.<\/p>\n<h2>What\u2019s Inside the Repository?<\/h2>\n<p>The repository includes eight examples, each demonstrating a different approach to SQL Server integration with .NET Aspire. Let\u2019s take a closer look at what each one offers.<\/p>\n<h3>1. Base Sample<\/h3>\n<p><strong>A minimal .NET Aspire application<\/strong> with a simple WebAPI project. This serves as a foundation to build upon, adding SQL Server or Azure SQL integration as needed.<\/p>\n<h3>2. Bring-Your-Own-SQL-Server<\/h3>\n<p>This builds on the <strong>Base Sample,<\/strong> updating the WebAPI to connect to an <strong>existing SQL Server instance<\/strong> via a provided <strong>connection string<\/strong>. This is the simplest way to integrate SQL Server in Aspire without deploying a new database.<\/p>\n<h3>3. Aspire-Hosted SQL Server<\/h3>\n<p>In this version, <strong>SQL Server is deployed and managed by Aspire<\/strong>, running inside an OCI container. This introduces the <code>Aspire.Hosting.SqlServer<\/code> library on the server side, while the WebAPI project still fetches the connection string via an Aspire-provided environment variable.<\/p>\n<h3>4. Aspire-Hosted SQL Server + DbUp<\/h3>\n<p>This expands on the previous example by <strong>adding database schema deployment<\/strong> using <a href=\"https:\/\/dbup.readthedocs.io\/en\/latest\/\">DbUp<\/a>.<\/p>\n<ul>\n<li>SQL Server is still managed by Aspire.<\/li>\n<li>The WebAPI project now gets the connection via Dependency Injection instead of reading from environment variables.<\/li>\n<li>Database schema deployment is fully automated via a new Aspire-orchestrated <code>DatabaseDeploy<\/code> application using the <code>DbUp<\/code> library.<\/li>\n<\/ul>\n<h3>5. Aspire-Hosted SQL Server + Database Project<\/h3>\n<p>Instead of DbUp, this example introduces a <strong>declarative database deployment<\/strong> approach using a <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/tools\/sql-database-projects\/sql-database-projects?view=sql-server-ver16\">Database Project<\/a>. The database schema is now defined and version-controlled in a structured way, and Aspire orchestrates its deployment using <code>CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects<\/code>.<\/p>\n<h3>6. Aspire-Hosted SQL Server + EF Core<\/h3>\n<p>This version <strong>integrates Entity Framework Core (EF Core)<\/strong>, allowing the WebAPI project to interact with SQL Server using EF\u2019s DbContext.<\/p>\n<ul>\n<li>EF Core\u2019s dependency injection is powered by <code>Aspire.Microsoft.EntityFrameworkCore.SqlServer<\/code>.<\/li>\n<li>Migrations are applied automatically using an Aspire-orchestrated Worker Service.<\/li>\n<\/ul>\n<p>Note: For simplicity, the EF Core models and migrations are defined inside the WebAPI project, though best practices would involve using a separate project.<\/p>\n<h3>7. Aspire-Hosted SQL Server + DbUp + Data API Builder<\/h3>\n<p>This sample builds upon the previous DbUp sample but removes the WebAPI project entirely\u2014because now, <strong><a href=\"https:\/\/aka.ms\/dab\">Data API Builder (DAB)<\/a> handles everything<\/strong>!<\/p>\n<ul>\n<li><strong>DAB exposes the database as REST and GraphQL APIs,<\/strong> eliminating the need for manual API development.<\/li>\n<li><strong>DAB is fully orchestrated by Aspire<\/strong>, using <code>CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder<\/code>.<\/li>\n<\/ul>\n<p>Perfect for rapid backend development when you need to quickly expose data via APIs.<\/p>\n<h3>8. End-To-End Jamstack &#8220;ToDo List&#8221;<\/h3>\n<p>A full-stack example that combines:<\/p>\n<ul>\n<li><strong>Vue.js frontend<\/strong><\/li>\n<li><strong>Data API Builder (DAB) backend<\/strong><\/li>\n<li><strong>SQL Server database<\/strong> deployed via a Database Project<\/li>\n<li><strong>Node.js application<\/strong> (<code>TodoApp.Frontend<\/code>), orchestrated with Aspire\u2019s <code>CommunityToolkit.Aspire.Hosting.NodeJS.Extensions<\/code><\/li>\n<\/ul>\n<p>This demonstrates how you can build <strong>modern web apps<\/strong> with an entirely <strong>Aspire-managed backend<\/strong> powered by SQL Server + DAB.<\/p>\n<h2>Why This Matters<\/h2>\n<p>If you\u2019re building cloud-native applications with <strong>SQL Server and .NET Aspire<\/strong>, this repository provides practical, real-world samples to get started quickly.<\/p>\n<p>Key benefits of these approaches:<\/p>\n<ul>\n<li><strong>Faster integration<\/strong> of SQL Server and Azure SQL with .NET Aspire<\/li>\n<li><strong>Multiple options<\/strong>: BYO SQL Server, Aspire-hosted containers, or declarative database projects<\/li>\n<li><strong>Automated database provisioning<\/strong> with DbUp, Database Projects, or EF Core migrations<\/li>\n<li><strong>Zero-code backends with Data API Builder (DAB)<\/strong>, enabling instant REST and GraphQL APIs<\/li>\n<li><strong>Full-stack orchestration<\/strong> with Aspire for databases, APIs, and frontend applications<\/li>\n<\/ul>\n<h2>Get Started \ud83d\ude80<\/h2>\n<p>Explore the repository here: <a href=\"https:\/\/github.com\/Azure-Samples\/azure-sql-db-aspire\">azure-sql-db-aspire<\/a><\/p>\n<p>Try out the samples, see what works for your needs, and feel free to contribute or provide feedback!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":24720,"featured_media":4348,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[444,652,1,597],"tags":[645,560,653,654,655],"class_list":["post-4339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-aspire","category-azure-sql","category-data-api-builder-2","tag-net-aspire","tag-data-api-builder","tag-database-project","tag-dbup","tag-ef-core"],"acf":[],"blog_post_summary":"<p>I&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/24720"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=4339"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/4339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/4348"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=4339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=4339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=4339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}