I worked with Entity Framework in Visual Studio 2017 without problems. Updated to Visual Studio 2019 and there was a problem connecting to the local server.
System.Data.SqlClient.SqlException: "A network or specific instance error occurred while establishing a connection to SQL Server. The server could not be found or is unavailable. Make sure the instance name is correct and that remote connections are allowed on SQL Server. (Provider : SQL Network Interfaces, error: 50 - A Local Database Runtime error occurred. An unexpected error occurred while calling the LocalDB instance API method. For more information about the error, see the Windows Application Event Log.`
This error is knocked out upon first access to the database.
PS: Entity Framework is installed
I have installed SQL Server 2016 Express LocalDB. I installed the SQL Server 2012 Express LocalDB, but this did not work. It's test project.
My context class:
public class ContextDb : DbContext
{
public ContextDb() : base("name=ContextDb")
{
}
public DbSet<User> Users { get; set; }
}
My connection string:
<connectionStrings>
<add name="ContextDb"
connectionString="data source=(LocalDb)\MSSQLLocalDB;initial catalog=TestDb.ContextDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>