We have three projects.
The two website projects have reference to Company.Domain
.
Our EF 5 DbContext
lives in Company.Domain.Data.EntityFramework
and it looks like this:
using System.Data.Entity;
using Company.Domain.Data.EntityFramework.Entities;
namespace Company.Domain.Data.EntityFramework.
{
public class CompanyEntities : DbContext
{
public DbSet<Notification> Notifications { get; set; }
public DbSet<Report> Reports { get; set; }
public DbSet<ReportSection> ReportSections { get; set; }
public DbSet<ReportPage> ReportPages { get; set; }
// brevity brevity
}
}
We have enabled migrations and successfully used the tool in the past so I'm not sure why we are having issues now. Our migrations configuration lives in Company.Domain.Data.EntityFramework.Migrations
and looks like this:
namespace Company.Domain.Data.EntityFramework.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using Company.Domain.Data.EntityFramework;
public class Configuration : DbMigrationsConfiguration<CompanyEntities>
{
public Configuration()
{
MigrationsDirectory = @"Data\EntityFramework\Migrations";
AutomaticMigrationsEnabled = false;
}
protected override void Seed(CompanyEntities context)
{
// empty at the moment
}
}
}
We then have an App.config
file in the root of the Company.Domain
project and it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="CompanyEntities" providerName="System.Data.SqlClient" connectionString="Data Source=devsql;Initial Catalog=CompanyEntities;uid=XXXXX;pwd=XXXXX;MultipleActiveResultSets=True;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Our database lives on another server on the network. I'm able to connect to it in SQL Server Management Studio and our applications are able to connect at runtime just fine. However, when I try to run add-migration
or even update-database
I get the following error:
System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: 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.
I've even reverted my changes to the model and then ran update-database
just to see if it would say 'database is on latest migration' but I still got the above error. I've poured over the connection string in App.config
over and over. I cannot figure out why migrations won't connect but both of our website projects work just fine at runtime. Migrations have worked in the past. Below are the migrations in solution explorer compared with those found in the __MigrationHistory
table in the database.
It looks like I should be able to run update-database
and have it tell me that it is up to date, but I get that error instead.
As I understand it, migrations shouldn't be paying any attention to our two website projects when I'm running migrations commands, but I poured over their Web.config files as well just in case. The connection strings are identical to App.config.
I've even tried completely uninstalling and removing the EF 5 package from the projects and reinstalling. Same issue >:(
Did your start project contains web.config or app.config as EF use the start project as source of the connection string