Mvc实体框架工作异常 - providerincompatibleexception未被用户代码处理 [英] Mvc entity frame work exception-providerincompatibleexception was unhandled by user code

查看:100
本文介绍了Mvc实体框架工作异常 - providerincompatibleexception未被用户代码处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器类 -

Controller Class-

public class HomeController : Controller
    {
        OdeToFood2Db _db = new OdeToFood2Db();
        public ActionResult Index()
        {
            var model = _db.Restaurants.ToList();
            return View(model);
        }





实体框架工作DBCOntext类 -



Entity Frame work DBCOntext class-

public class OdeToFood2Db:DbContext
    {
        public DbSet<Restaurant> Restaurants { get; set; }
        public DbSet<RestaurantReview> Reviews { get; set; }
    }





网络配置 - >



Web Config-

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-OdeToFood2-20170119174541;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-OdeToFood2-20170119174541.mdf" providerName="System.Data.SqlClient" />





执行Controller类时 - 异常即将来临 -



On execution of the Controller class- the exception is coming-

ProviderIncompatibleException was unhandled by user code




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.





我尝试过:



我有例外但无法解决,请帮助



What I have tried:

I am having the exception and not able to resolve, please help

推荐答案

微软的描述例外: ProviderIncompatibleException Class(System.Data) [ ^ ]表示一些可能的情况,谷歌搜索(见下文)强烈暗示它很可能是你的连接字符串。



谷歌搜索:提供不兼容的异常 [ ^ ]
Microsoft's description of the exception: ProviderIncompatibleException Class (System.Data)[^] indicates a few possible scenarios and googling (see below) strongly suggests that it is most likely your connection string.

Google search: provider incompatible exception[^]


我的查询字符串是 -

My Query String is-
<add name="DefaultConnection" connectionString="Data Source=(Localdb)\v11.0;Initial Catalog=aspnet-OdeToFood-20161225201813;Integrated Security=True" providerName="System.Data.SqlClient" />





我从数据库资源管理器获取的内容 - > DataCOnnection->默认连接是 -

连接字符串 - >



And what i got from database explorer->DataCOnnection->Default Connection is -
Connection String->

Data Source=(Localdb)\v11.0;Initial Catalog=aspnet-OdeToFood-20161225201813;Integrated Security=True



provider-


provider-

.NET Framework Data Provider for SQL Server



似乎正确,仍无法正常工作


Seems its correct, still not working


这篇关于Mvc实体框架工作异常 - providerincompatibleexception未被用户代码处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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