The title of this post is a cryptic error message that I got when trying to use EntityFramework 6 (EF6 - .NET Framework, not EF Core) in an ASP.NET MVC 5 (not ASP.NET Core). The context of the usage is when I was trying to update the database in Nuget PackageManager console with the following command:
Update-Database
I looked at the connection string hard and wrestled with it for many hours up to no avail. The reason was that the rest of the error message said that there was a failure to connect to SQL Server and naturally the reason for my wrestling with the connection string was the hope of connecting with the SQL Server.
Strangely, the SQL Server Management Studio was able to connect with the SQL Server instance with the same username and password. And, so could the Visual Studio Server Explorer. In fact, I also tried copying the connection string from the Visual Studio Server Explorer Advanced Settings for the SQL Server instance. Nothing worked. Then it flashed to me that there must be something wrong with the way we are setting up the EntityFramework migration of the database. We reinstalled the EntityFramework package and issued the following commands in the PackageManager console:
Enable-Migration
Add-Migration Initial
Update-Database
This also didn't work!!
Finally I saw that the subclass of DbContext class that was declared in the project wasn't calling the base class's (DbContext class) constructor:
public AppDbContext : DbContext
{
public AppDbContext() : base("name=ConnectionString")
{ }
}
Putting the above constructor finally made the update-database command work. The name=ConnectionString is the name attribute of the XML element in web.config that has the connection string of the database. Great Lord! We went through such hoops and loops to get this to work and the solution lay somewhere else.