SqlConnection.Open fails and throw Login failed for user 'sa' error suddenly after upgrading Entity Framework Core from 3.1.4 to 3.1.8

Stack Overflow Asked by fingers10 on December 10, 2020

I was using Microsoft.EntityFrameworkCore v3.1.4 Nuget Package in my ASP.NET Core 3.1 Web API project to read and write to database using TransactionScope. I referred the official documentation for doing that.

Here is my code:

using (var scope = new TransactionScope(TransactionScopeOption.Required,
                new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
    using (var connection = new SqlConnection(_context.Database.GetDbConnection().ConnectionString))
        connection.Open(); // ---> throws error - "Login failed for user 'sa'."

        // Run raw ADO.NET command in the transaction
        var command = connection.CreateCommand();

        // updating document security in tdoc table
        command.CommandText = query;

        // --------------------- Remaining Code goes here. Removed for brevity--------------

Here are the Nuget packages used:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

After updating above Nuget packages from 3.1.4 to 3.1.8, connection.Open() suddenly throws the following error:

Login failed for user ‘sa’

After some googling I found that I need to add Persist Security Info=True; in my connection string.

My previous connection string:


I changed this to:

Persist Security Info=True;Data Source=ServerName;Initial Catalog=DatabaseName;User Id=sa;Password=password

But now I get this error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Shared Memory Provider, error: 40 – Could not open a connection to SQL Server)

when I execute context.DbSet.FirstOrDefault().

Please assist on how to fix this breakage.

Add your own answers!

Related Questions

How to insert multiple images in the Django blog app?

1  Asked on November 29, 2021 by waw-waw


Filter out Certain Words and Match only EXACT Words

1  Asked on November 27, 2021 by askmeaquestion1234


soup.find returning “none” only sometimes?

2  Asked on November 27, 2021 by c120


Raise float into the power – print formula

1  Asked on November 27, 2021 by markl


Conditional Window Functions

1  Asked on November 27, 2021 by caerus


unable to load font awesome icons in html

1  Asked on November 27, 2021 by vasilis-skentos


Why the method is returning padEnd as undefined?

1  Asked on November 27, 2021 by dev101


React js .bind(this) in hooks

1  Asked on November 27, 2021 by soukaina-benchekroun


How to get a specific name from another array by its id?

1  Asked on November 27, 2021 by ahmed-eid


Insertion Sort on a String Array

1  Asked on November 27, 2021 by 101001


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir