C# No connection string named 'DataModelContainer' could be found in the application config file.

 

 

System.InvalidOperationException   HResult=0x80131509   Message=No connection string named 'DataModelContainer' could be found in the application config file.   Source=EntityFramework   StackTrace:    在 System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()    在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()    在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)    在 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()    在 System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()    在 System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()    在 DAL.ScenicDal.GetScenicArea(String cityName) 在 C:\Users\liuzhao\source\repos\Travel\DAL\ScenicDal.cs 中: 第 25 行    在 BLLs.ScenicAreaBll.GetScenicAreas(String name) 在 C:\Users\liuzhao\source\repos\Travel\BLLs\ScenicAreaBll.cs 中: 第 15 行    在 Travel.Controllers.TravelController.GetScenicArea(String city) 在 C:\Users\liuzhao\source\repos\Travel\Travel\Controllers\TravelController.cs 中: 第 26 行    在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__3(Object instance, Object[] methodParameters)    在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)    在 System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

 

 

由于我更改了模型实体,导致重新生成了sql server的连接配置

<connectionStrings>

    <add name="DataModelContainer" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LIUZHAO110;initial catalog=TravelsDb;user id=sa;password=123;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

  </connectionStrings>

然而在其他项目的web.config下的配置不会更新,比如我的api接口项目中

<connectionStrings><add name="TravelsDbEntities" connectionString="metadata=res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LIUZHAO110;initial catalog=TravelsDb;user id=sa;password=123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

这里命名还是之前的命名,所以导致这个问题,所以更改name后,其他所有的用到上下文的地方都得手动的更改过来,就是说将模型所在项目中的上面内容copy替换就行了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值