PacktPublishing / Pragmatic-Microservices-with-CSharp-and-Azure

Pragmatic Microservices with C# and Azure, published by Packt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Login failed for user 'sa' when creating the db in Chapter 5

andriyptashka opened this issue · comments

Could not connect to the db via Azure Data Studio either with the same error.

image

After some digging I went to inspect the container and checked the MSSQL_SA_PASSWORD value. It was completely different from the one in the instructions MSSQL_SA_PASSWORD=Pa$$w0rd. Once you use the password form the container - it seems to be working fine.

I missed updating the readme file here. With a previous Aspire version we had to set the password (and retrieve it using the secrets) and need to pass it to the app model for the database. With the changes it's simpler now.
I'll update the readme file, thanks!

I already had password with SQL updated in the book and in samples, thus it was working as expected. I've added more details to the readme file of chapter 5.
What you might run into is that the docker volume was already created with the other password you mentioned:

Running the application with this configuration:

var sqlServer = builder.AddSqlServer("sql")
    .WithDataVolume("codebreaker-sql-data", isReadOnly: false)
    .AddDatabase("CodebreakerSql");

Creates a volume with a random password. This only works once, because next time a new password is created, and this does not match the one stored.

Setting Parameters:sql-password to a password, always this password is used, and you can re-run the application keeping the data.

Another option is to retrieve the password from parameters, and pass it to the AddSqlServer method:

var sqlPassword = builder.AddParameter("SqlPassword", secret: true);

var sqlServer = builder.AddSqlServer("sql", sqlPassword)
    .WithDataVolume("codebreaker-sql-data", isReadOnly: false)
    .AddDatabase("CodebreakerSql");

Here, the configuration Parameters:SqlPassword needs to be set.

I hope this helps.

Converting this to a discussion.