Hi,
I have a project running on .NET 9 using .NET Aspire. When I start the project for the first time, everything works fine. But if I stop and start it again, I see the following error in the Aspire logs related to the database:
Login failed for user 'sa'. Reason: Password did not match that for the login provided.
Also, the database and server status show as Unhealthy.
Here is the relevant part of my Program.cs file in the Aspire project:
using Projects;
var builder = DistributedApplication.CreateBuilder(args);
var db = builder
.AddSqlServer("sql")
.WithLifetime(ContainerLifetime.Persistent)
.WithDataVolume(name: "MyDb", isReadOnly: false)
.AddDatabase("MyDb");
builder.AddProject<AbsenceFlow_Web>("web")
.WithReference(db).WaitFor(db);
builder.Build().Run();
If I go into Docker Desktop and delete everything related to the SQL database, then start the project again through Aspire, it works - but all my data is lost.
What could be causing this issue? How can I keep my database persistent without losing data or getting the login error?
Thanks in advance for any help!