实体框架6与SQL Server 2012给出System.Data.Entity.Core.ProviderIncompatibleException [英] Entity Framework 6 with SQL Server 2012 gives System.Data.Entity.Core.ProviderIncompatibleException

查看:272
本文介绍了实体框架6与SQL Server 2012给出System.Data.Entity.Core.ProviderIncompatibleException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Visual Studio 2012,我正在使用与EF 6的实体框架堆栈。我做的都是正确的,但在添加迁移时我收到错误。


System.Data.Entity.Core.ProviderIncompatibleException


这里是类

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

上下文文件



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);
}

而对于connctionstring的web.config文件部分

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

当我尝试添加迁移时,我收到错误:


System.Data.Entity.Core.ProviderIncompatibleException:从数据库获取提供者信息时发生错误。这可能是由实体框架使用错误的连接字符串引起的。检查内部异常的详细信息,并确保连接字符串正确。 ---> System.Data.Entity.Core.ProviderIncompatibleException:提供程序没有返回一个ProviderManifestToken字符串。 --->



System.Data.SqlClient.SqlException:与SQL Server建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 定位服务器/实例指定错误)



解决方案

>尝试这个确保您的ShoppingCartContext所在的项目是启动项目或执行add-migration命令时包含参数-startupprojectname ex。 add-migration -startupprojectname yourprojectname


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)

解决方案

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

这篇关于实体框架6与SQL Server 2012给出System.Data.Entity.Core.ProviderIncompatibleException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆