Skip to content

[SQLProjects] Deployment stuck in "Pending" state when using Aspire.Hosting.Azure.Sql locally #529

Closed as not planned

Description

@yorek

Describe the bug

When using AddAzureSqlServer("").RunAscontainer() using the Aspire.Hosting.Azure.Sql package, the deployment just hangs. No error, no logs...just hanging, and deployment reports "Pending" as a status.

Regression

No response

Steps to reproduce

var sqlSrv = builder.AddAzureSqlServer("sql")
    .RunAsContainer();    

var sqlDb = sqlSrv.AddDatabase("aspiretodo");

var dbPrj = builder.AddSqlProject<Projects.TodoDB>("tododb")    
    .WithReference(sqlDb)    
    .WaitFor(sqlDb);

Expected behavior

Deploy the database project

Screenshots

No response

IDE and version

Other

IDE version

VS Code

Nuget packages

<PackageReference Include="Aspire.Hosting.AppHost" Version="9.1.0" />
<PackageReference Include="Aspire.Hosting.Azure.Sql" Version="9.1.0" />
<PackageReference Include="Aspire.Hosting.NodeJs" Version="9.1.0" />
<PackageReference Include="Aspire.Hosting.SqlServer" Version="9.1.0" />
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder" Version="9.2.0" />
<PackageReference Include="CommunityToolkit.Aspire.Hosting.NodeJS.Extensions" Version="9.2.0" />
<PackageReference Include="CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects" Version="9.2.1" />

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Activity

  1. aaronpowell commented on Mar 4, 2025

    @aaronpowell
    Member

    Related to #434 I believe

  2. ErikEJ commented on Mar 4, 2025

    @ErikEJ
    Contributor
  3. aaronpowell commented on Mar 4, 2025

    @aaronpowell
    Member

    That looks like a good catch. I wonder how we can best tackle it, do we create a separate Hosting.SqlDatabaseProjects.Azure integration or roll it into the existing. Rolling with the existing does mean that if you're not using Azure you still end up with Azure in the dependency stack, but a separate integration feels like major overkill

  4. ErikEJ commented on Mar 5, 2025

    @ErikEJ
    Contributor

    What is the difference between

    builder.AddAzureSqlServer("sql")
    .RunAsContainer();

    And

    .AddSqlServer

    Is it deployment support or anything else?

  5. ErikEJ commented on Mar 5, 2025

    @ErikEJ
    Contributor

    if you're not using Azure you still end up with Azure in the dependency stack,

    @aaronpowell If you use Microsoft.Data.SqlClient you end up with a lot of Azure "stuff" anyway currently.

  6. ErikEJ commented on Mar 5, 2025

    @ErikEJ
    Contributor

    What if the Resource classes here were in a seperate package?

    https://github.com/dotnet/aspire/tree/main/src/Aspire.Hosting.Azure.Sql

  7. aaronpowell commented on Mar 5, 2025

    @aaronpowell
    Member

    Thinking through this, the question, in my mind, is "what happens if it's an Azure SQL resource?", as in, not configured to be a container locally, just purely an Azure SQL resource - should (can?) it deploy to Azure SQL?

    Since the SqlDatabaseProjects package doesn't produce anything in the manifest, it means we have to be careful on how the support works. Take this code for example:

    var sqlSrv = builder.AddAzureSqlServer("sql");    
    
    var sqlDb = sqlSrv.AddDatabase("aspiretodo");
    
    var dbPrj = builder.AddSqlProject<Projects.TodoDB>("tododb")    
        .WithReference(sqlDb)    
        .WaitFor(sqlDb);

    What happens when you use Aspire to deploy? Well, the AddSqlProject is ignored from the manifest, but you have the expectation that something should have happened because running locally it did deploy to the Azure resource. There's an obvious argument against using the Azure SQL database for local development, but it's something people can, and may need to, do.

    So back to the problem at hand, I think this works (I haven't tested):

    var dbPrj = builder.AddSqlProject<Projects.TodoDB>("tododb");
    
    var sqlSrv = builder.AddAzureSqlServer("sql")
        .RunAsContainer(resource => {
          // find databases from the resource, or maybe via the builder
        });    
    
    var sqlDb = sqlSrv.AddDatabase("aspiretodo");

    The callback provided to RunAsContainer receives the IResourceBuilder<SqlServerServerResource> which does have the names of all the databases on it, and you can use that to get the IResourcesCollection from the builder and then grab it. It wouldn't be "pretty", but it'd be doable.

  8. yorek commented on Mar 7, 2025

    @yorek
    Author

    Hey both, from my understanding the RunAsContainer creates a local container to simulate Azure SQL db locally. I would expect during the deployment phase that an Azure SQL DB is created instead of having SQL Server deployed in a container in Azure.

  9. yorek commented on Mar 7, 2025

    @yorek
    Author

    "what happens if it's an Azure SQL resource?", as in, not configured to be a container locally, just purely an Azure SQL resource - should (can?) it deploy to Azure SQL?

    I think it should, right? Conceptually it would be equivalent to run EF Core migrations against Azure SQL instead of SQL Server and that is expected to work right away

  10. aaronpowell commented on Mar 7, 2025

    @aaronpowell
    Member

    "what happens if it's an Azure SQL resource?", as in, not configured to be a container locally, just purely an Azure SQL resource - should (can?) it deploy to Azure SQL?

    I think it should, right? Conceptually it would be equivalent to run EF Core migrations against Azure SQL instead of SQL Server and that is expected to work right away

    Yep, I'd expect so (I'm just unfamiliar with the tooling that powers the integration).

    Deployment is more complex though, as you need to run the dacpac deployment as part of the Bicep files, which I guess you'd do as a custom script in Bicep, but you'd need to somehow upload the dacpac to somewhere that it can be downloaded in the script run. This is why it's not currently enabled for deployment - deployment makes it complex.

  11. ErikEJ commented on Mar 7, 2025

    @ErikEJ
    Contributor

    @yorek @aaronpowell

    the RunAsContainer creates a local container to simulate Azure SQL db locally.

    Yeah, I dug into the source - since there is no "Azure SQL Container" it spins up a plain SQL Server 2022 container...

    Deployment is more complex though, as you need to run the dacpac deployment as part of the Bicep files...

    Yeah, exactly! And I absolutely agree that this is a noble end goal!

    I am not an expert, but maybe the following options are worth investigating:

    • The owner of the ARM provider for Azure SQL could potentially add support for continous deployment of a .dacpac, similar to the initial "sampleName" property that is available today. Then that would also become available in Bicep - but as Aaron mentioned, there are probably some challenges around storage/upload of the .dacpac and maybe execution of it (or perhaps that is what "sampleName" already does?
    • I understand that 'azd' has an extensibility model, but have not dug further into it.
  12. yorek commented on Mar 21, 2025

    @yorek
    Author

    Yeah, I dug into the source - since there is no "Azure SQL Container" it spins up a plain SQL Server 2022 container...

    Yep, that is fine and expected

  13. ErikEJ commented on Mar 24, 2025

    @ErikEJ
    Contributor

    @yorek We seem to be discussing at least two topics here

    • local deployment support
    • general production deployment support for SQL Projects

    Maybe you should open a new issue for the second topic?

    Did you try what @aaronpowell suggested above?

    @jmezach Any thoughts on this issue - it would be a great scenario to support.

  14. jmezach commented on Mar 24, 2025

    @jmezach
    Contributor

    @ErikEJ I would definitely want to support the ability to deploy a .dacpac to an Azure SQL-like container during local development. One might argue that at least for local-dev there really isn't a distinction between Azure SQL and SQL Server.

    Not sure why it gets stuck into a pending state though. If the target resource is not a SqlServerDatabaseResource, which I'm assuming is the case here, we start deploying as soon as all resources have been created (AfterResourcesCreatedEvent).

  15. 17 remaining items

  16. github-actions commented on Oct 13, 2025

    @github-actions
    Contributor

    We have noticed this issue has not been updated within 21 days. If there is no action on this issue in the next 14 days, we will automatically close it. You can use /stale-extend to extend the window.

  17. ErikEJ commented on Oct 13, 2025

    @ErikEJ
    Contributor

    @mitchdenny @davidfowl Any plans to improve this - or are we doing it wrong?

  18. ErikEJ commented on Oct 13, 2025

    @ErikEJ
    Contributor

    /stale-extend

  19. changed the title [-]Deployment stuck in "Pending" state when using Aspire.Hosting.Azure.Sql locally[/-] [+]SQL Project Deployment stuck in "Pending" state when using Aspire.Hosting.Azure.Sql locally[/+] on Oct 31, 2025
  20. changed the title [-]SQL Project Deployment stuck in "Pending" state when using Aspire.Hosting.Azure.Sql locally[/-] [+][SQLProjects] Deployment stuck in "Pending" state when using Aspire.Hosting.Azure.Sql locally[/+] on Nov 25, 2025
  21. ErikEJ commented on Nov 26, 2025

    @ErikEJ
    Contributor

    @afscrome @jmezach

    I tested this with Aspire 13 and version 13, still hanging on Waiting - @afscrome wonder if you have any ideas?

  22. afscrome commented on Nov 30, 2025

    @afscrome
    Contributor

    Looks like the Azure database resources aren't firing the ResourceReady event - I've raised microsoft/aspire#13253 for this.

  23. ErikEJ commented on Nov 30, 2025

    @ErikEJ
    Contributor

    @afscrome thanks, that was also my conclusion in issue 8383

  24. github-actions commented on Jan 15, 2026

    @github-actions
    Contributor

    We have noticed this issue has not been updated within 21 days. If there is no action on this issue in the next 14 days, we will automatically close it. You can use /stale-extend to extend the window.

  25. github-actions commented on Jan 29, 2026

    @github-actions
    Contributor

    This issue has been stale for 5 weeks and has been automatically closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Staleawaiting responseWaiting for the author of the issue to provide more information or answer a question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions