Eshoponcontainers: Login failed for 'sa'

Created on 8 Jan 2018  路  13Comments  路  Source: dotnet-architecture/eShopOnContainers

Hello,

I'm getting lots of "Login failed for 'sa'" errors while running the containers on macOS.

Is there a setting I need to change that is not specified in the guide (https://github.com/dotnet-architecture/eShopOnContainers/wiki/04.-Setting-eShopOnContainer-solution-up-in-a-Mac,-VS-for-Mac-or-with-CLI-environment--(dotnet-CLI,-Docker-CLI-and-VS-Code))?

Thanks!

Most helpful comment

Hello all,

I think I found the problem........

In the last commit I see at the moment, 60fc141, an update was made in the docker-compose.override.yml file.

The name of the variable for the password of the sa account was changed to sa_account

As I see here:

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker

the name of the variable must be (for the microsoft/mssql-server-linux:2017-latest)
MSSQL_SA_PASSWORD

I changed it and the application is up again........

Waiting for the fix to be applied on the dev branch, you can change the section sql.data to

sql.data:
environment:
- MSSQL_SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"

Thanks

All 13 comments

Check you assign more than 4gb memory to Docker in the Mac.
And no, those instructions should be enough
Looks like the SQL container might no be starting right in your environment

Hi, I'm getting same error. Right after localhost:5001 is opened up I got the "Login failed for 'sa'"
I've assigned more than 4gb but don't know what else should I check.
Thanks

Not sure what this can be as I've tried it in a Mac just a few days ago and it was working properly.
That kind of error is usually due to the fact that the SQL container was not properly deployed..
Can you try these:

  • Delete the SQL Server image from your local Docker
  • Try in a different machine, just in case.
    I'll try to test it in a Mac tomorrow or the day after and will confirm again.

@CESARDELATORRE Deleted all the containers and images, assigned 10GB memory to Docker and started from scratch. Still getting the same error.

Hi,

I have the same problem on a windows 10 machine.

After hitting F5, the "Login failed for sa" errors come out.

@CESARDELATORRE My Docker configuration is : 4 cores CPU + 4Go memory. I use Linux containers.

I use Visual Studio 2017 15.5.2. (NO PREVIEW).

The MVC page returns a 500 error after a minute or so. I hit a lot of times "Continue" in the debugger to obtain this.

The exception arrives on line :

                    context.Database
                    .Migrate();

in the
WebHostExtensions.cs source code.

It repeats two or three times.

A little part of the log:

[40minfo: Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext[0]
Migrating database associated with context IntegrationEventLogContext
Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogContext:Error: An error occurred while migrating the database used on context CatalogContext

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'sa'.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_02.<Execute>b__0(DbContext c, TState s) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func3 operation, Func3 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func2 operation, Func2 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func2 operation)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
at Microsoft.AspNetCore.Hosting.IWebHostExtensions.<>c__DisplayClass0_11.<MigrateDbContext>b__0() in D:\Projects\github\eShopOnContainers\src\BuildingBlocks\WebHostCustomization\WebHost.Customization\WebHostExtensions.cs:line 41 at Polly.Policy.<>c__DisplayClass57_0.<Execute>b__0(Context ctx, CancellationToken ct) at Polly.RetrySyntax.<>c__DisplayClass20_0.<WaitAndRetry>b__1(Context ctx, CancellationToken ct) at Polly.Retry.RetryEngine.Implementation[TResult](Func3 action, Context context, CancellationToken cancellationToken, IEnumerable1 shouldRetryExceptionPredicates, IEnumerable1 shouldRetryResultPredicates, Func1 policyStateFactory) at Polly.RetrySyntax.<>c__DisplayClass20_1.<WaitAndRetry>b__0(Action2 action, Context context, CancellationToken cancellationToken)
at Polly.Policy.Execute(Action2 action, Context context, CancellationToken cancellationToken) at Polly.Policy.Execute(Action action) at Microsoft.AspNetCore.Hosting.IWebHostExtensions.MigrateDbContext[TContext](IWebHost webHost, Action2 seeder) in D:\Projects\github\eShopOnContainers\src\BuildingBlocks\WebHostCustomization\WebHost.Customization\WebHostExtensions.cs:line 35
ClientConnectionId:c4a7c8b8-0c29-443b-aa43-4b80a09a71d9
Error Number:18456,State:1,Class:14
Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext:Information: Migrating database associated with context IntegrationEventLogContext
Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext:Information: Migrating database associated with context IntegrationEventLogContext
info: Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext[0]
Migrating database associated with context IntegrationEventLogContext
info: Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext[0]
Migrating database associated with context IntegrationEventLogContext
Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.IntegrationEventLogContext:Information: Migrating database associated with context IntegrationEventLogContext
fail: IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext[0]
An error occurred while migrating the database used on context PersistedGrantDbContext
System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'sa'.

Hi everybody

Seeing messages "login failed for sa" is expected and is because the SQL Server container takes more time to start and be ready to accept incoming connections.
When using docker compose up (or starting solution with VS) all containers are started, and even though there are dependencies established in compose file, those dependencies only affect the container startup, not the process in the container be ready to accept incoming connections.

Code in MVC, SPA and services is ready to handle these situations (with retries using Polly) so it should not be an issue. If, for any reason, SQL Server takes longer to start this can generate an issue. In those cases starting again the application should solve the issue.

Hello all,

I think I found the problem........

In the last commit I see at the moment, 60fc141, an update was made in the docker-compose.override.yml file.

The name of the variable for the password of the sa account was changed to sa_account

As I see here:

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker

the name of the variable must be (for the microsoft/mssql-server-linux:2017-latest)
MSSQL_SA_PASSWORD

I changed it and the application is up again........

Waiting for the fix to be applied on the dev branch, you can change the section sql.data to

sql.data:
environment:
- MSSQL_SA_PASSWORD=Pass@word
- ACCEPT_EULA=Y
ports:
- "5433:1433"

Thanks

@amihailes thank you, I used to get
An unhandled exception occurred while processing the request. HttpRequestException: Exception of type 'System.Net.Http.HttpRequestException' was thrown. Microsoft.eShopOnContainers.BuildingBlocks.Resilience.Http.ResilientHttpClient+<>c__DisplayClass9_0+<<GetStringAsync>b__0>d.MoveNext() in C:\Users\kemo\workspace\dotnet\ecommerce\eShopOnContainers\src\BuildingBlocks\Resilience\Resilience.Http\ResilientHttpClient.cs, line 100
and it fixed it for me.

Hi all again,

I looked more deeply on this issue.

In fact it's problem of lower/upper case.

As I use Linux Docker containers, the line

sa_password=Pass@word

doesn't work. I suppose it works on windows containers......

The good line for the Linux container is (upper case):

SA_PASSWORD=Pass@word

This works on Linux containers microsoft/mssql-server-Linux and I think it's also OK on the other type of containers.

For more information:

https://hub.docker.com/r/microsoft/mssql-server-linux/

Regards,

Adrian

Right, it is a bug introduced when testing a few days ago with Windows Containers. I just fixed it. Please, do a git pull. The Password specification for the SQL Container in Windows Containers is different format than in Linux. We'll add the Windows Containers format in the docker-compose.override.windows.yml.

Format for SQL Linux container:

  sql.data:         
    environment:              
      - MSSQL_SA_PASSWORD=Pass@word      
      - ACCEPT_EULA=Y
    ports:
      - "5433:1433"

Format for SQL Windows container:

  sql.data:
    environment:
      - sa_password=Pass@word
      - ACCEPT_EULA=Y
    ports:
      - "5433:1433" 

I'm closing the issue. Thanks for the heads-up.

I tested that SA_PASSWORD also works ok in Linux as well as MSSQL__SA_PASSWORD.
We'll keep SA_PASSWORD so it could be compatible for Windows Containers, too.

Hi.

That's exactly what I wrote in my last comment.

@amihailes - Agree, your suggestion is probably the best choice. We were originally using MSSQL_SA_PASSWORD for SQL Server on Linux container, but that won't work for Windows Containers.
I still have to test SA_PASSWORD (uppercase) with Windows Containers, though.

Was this page helpful?
0 / 5 - 0 ratings