Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 6 with SQL Server 2012 gives System.Data.Entity.Core.ProviderIncompatibleException

I have Visual Studio 2012 and I'm using the Entity Framework stack with EF 6. I did all correct but while adding migration I am getting the error .

System.Data.Entity.Core.ProviderIncompatibleException

Here are the classes

public class Order
{
    public virtual int OrderID { get; set; }
}

The context file

public ShoppingCartContext() : base("ShoppingCartDb")
{
        Database.SetInitializer<ShoppingCartContext>(new DropCreateDatabaseAlways<ShoppingCartContext>());
}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
        #region Entity Framework 6 RC-1
        modelBuilder.Properties().Where(x => x.Name == x.DeclaringType.ToString() + "ID")
                .Configure(x => x.IsKey());

        modelBuilder.Properties<DateTime>()
                .Configure(x => x.HasColumnType("datetime2"));
        #endregion

        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
    }

And the web.config file section for connctionstring

<connectionStrings>
   <add name="ShoppingCartDb" 
        connectionString="Server=Localhost;Database=ShoppingCartEfDb;User Id=sa;Password=xxxxxxxxxx" 
        providerName="System.Data.SqlClient" />
</connectionStrings>

I am getting the error whenever I am trying to add migration as :

System.Data.Entity.Core.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.Entity.Core.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. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

like image 749
Joy Avatar asked Sep 03 '13 04:09

Joy


People also ask

Which of the below is used for Entity Framework core with SQL Server?

Entity Framework Extensions EF Core - SQL Server Provider. Microsoft SQL Server is a relational database management system (RDBMS) that supports a wide variety of transaction processing, business intelligence and analytic applications in corporate IT environments.

Which package is needed to work with Entity Framework with SQL Server?

Here, we want to access MS SQL Server database, so we need to install Microsoft. EntityFrameworkCore. SqlServer NuGet package. To install the DB provider NuGet package, right click on the project in the Solution Explorer in Visual Studio and select Manage NuGet Packages..

What is Entity Framework core SQL Server?

Entity Framework Core is a modern object-database mapper for . NET. It supports LINQ queries, change tracking, updates, and schema migrations. EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.


1 Answers

Try this. Make sure that the project that your ShoppingCartContext is in, is the start up project or when executing the add-migration command include the parameter -startupprojectname ex. add-migration -startupprojectname yourprojectname

like image 174
Jelard Macalino Avatar answered Sep 21 '22 03:09

Jelard Macalino