Specified username in connection string gets replaced at runtime


I have a web site project as an entry point and defined the connection string there:

"ConnectionStrings": {
    "DataPlaygroundConnection": "Server=DataPlayhouse;Database=BusinessHandshake;User ID=bhuser1;Password=bh@12345;MultipleActiveResultSets=True;Connect Timeout=360;App=Company - Portal - Staging"

I started facing issues just recently that when running, I'd get Login failed for user 'bhuser1' error. But the credentials are working as I can connect to DB with any DB Manager (SSMS). Then I added Serilog to understand whats happening as the exception was thrown from Program.cs

After adding Serilog, I find this exception block:

10/20/2020 07:54:49 +04:00 Application Starting.
10/20/2020 07:54:49 +04:00 Using an in-memory repository. Keys will not be persisted to storage.
10/20/2020 07:54:49 +04:00 Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
10/20/2020 07:54:49 +04:00 No XML encryptor configured. Key {a012bed6-42e0-475d-a11d-44ae3a5599a9} may be persisted to storage in unencrypted form.
10/20/2020 07:54:58 +04:00 An error occurred using the connection to database '"BusinessHandshake"' on server '"DataPlayhouse"'.
10/20/2020 07:54:58 +04:00 An exception occurred while iterating over the results of a query for context type '"Folio.Infrastructure.Data.Contexts.PlaygroundBiContext"'."
""Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user 'bhuser1'.

The credentials in the json file are correct and I am able to use the same credentials in Azure Studio to connect to the database.

I do not have any customization code in context:

public partial class PlayHouseContext : DbContext

    public PlayHouseContext()

    public PlayHouseContext(DbContextOptions<PlayHouseContext> options)
        : base(options)

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        if (!optionsBuilder.IsConfigured)

I have a similar error on my local dev machine: SqlException: Login failed for user 'bhuser1'.

On my dev machine, the credentials are correct and I can use SSMS to easily access the said DB and all the elements within.

I'm unable to understand this one.

asked on Stack Overflow Oct 20, 2020 by Hassan Gulzar • edited Oct 20, 2020 by Dale K

1 Answer


Thanks @DaleK.

Trusted_Connection means windows authentication. I had to remove that and do the same in the appsettings.Development.json as well.

answered on Stack Overflow Feb 1, 2021 by Hassan Gulzar

User contributions licensed under CC BY-SA 3.0