Entity Framework - The underlying provider failed on ConnectionString(实体框架 - 基础提供程序在 ConnectionString 上失败)
问题描述
在使用实体框架时,我已将其拆分为自己的项目:
While using the Entity Framework I have split it out to it's own project:
- RivWorks.Model - 包含实体模型
- RivWorks.Controller - 使用实体模型并包含商业规则
- RivWorks.View.Web - 网站
- RivWorks.View.Services - WCF 项目
网站上的一切都运行良好.我可以调用控制器并返回一个有效的模型.当我从 Web.Service 尝试同样的事情时,我收到了这个错误:
Everything in the web site is working fine. I am able to call into the Controller and get a valid Model back. When I try the same thing from the Web.Service I am getting this error:
错误:
ConnectionString 上的基础提供程序失败.
堆栈跟踪:
在 System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
在 System.Data.EntityClient.EntityConnection..ctor(String connectionString)
在 System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
在 System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
在 RivWorks.Model.Entities.RivFeedsEntities1..ctor(String connectionString)
在 RivWorks.Model.FeedStoreReadOnly..ctor(String connectionString)
在 RivWorks.Controller.ProductManager.LookupProduct(String productID, String sku, String urlRef, String env, String logPath)
ERROR:
The underlying provider failed on ConnectionString.
STACK TRACE:
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
at RivWorks.Model.Entities.RivFeedsEntities1..ctor(String connectionString)
at RivWorks.Model.FeedStoreReadOnly..ctor(String connectionString)
at RivWorks.Controller.ProductManager.LookupProduct(String productID, String sku, String urlRef, String env, String logPath)
我有点困惑,为什么并仔细研究错误日志,我终于发现连接字符串没有从网站的配置文件中读取.所以,我添加了一些代码来捕捉它,现在,硬编码了这些值.喜欢:
I am a bit confused as to why and digging through the error logs I finally figured out the connection strings were not being read from the Web Site's config file. So, I added some code to catch that and, for now, hard coded the values in. Like:
public dataObjects.NegotiateSetup LookupProduct(string productID, string sku, string urlRef, string env, string logPath)
{
string feedConnString = "";
string rivConnString = "";
log.InitializeLogFile(logPath);
dataObjects.NegotiateSetup resultSet = new dataObjects.NegotiateSetup();
try { feedConnString = AppSettings.FeedAutosEntities_connString; }
catch { feedConnString = @"metadata=res://*/Entities.FeedEntities.csdl|res://*/Entities.FeedEntities.ssdl|res://*/Entities.FeedEntities.msl;provider=System.Data.SqlClient;provider connection string='Data Source=***.***.***.***;Initial Catalog=******;Persist Security Info=True;User ID=******;Password="******";MultipleActiveResultSets=True'"; }
try { rivConnString = AppSettings.RivWorkEntities_connString; }
catch { rivConnString = @"metadata=res://*/Entities.RivEntities.csdl|res://*/Entities.RivEntities.ssdl|res://*/Entities.RivEntities.msl;provider=System.Data.SqlClient;provider connection string='Data Source=******;Initial Catalog=******_Dev;Persist Security Info=True;User ID=******;Password="******";MultipleActiveResultSets=True'"; }
try
{
using (RivFeedsEntities1 _dbFeed = new FeedStoreReadOnly(feedConnString).ReadOnlyEntities())
{
using (RivEntities _dbRiv = new RivWorksStore(rivConnString).NegotiationEntities())
{
但是,唉,它仍然给我上面的错误!任何想法为什么?
But, alas, it is still giving me the above error! Any ideas why?
推荐答案
我知道你一直在弄乱你的连接字符串来清理它们,但我猜你没有把 "
的密码在哪里?
I know you've been mucking around with your connection strings to sanitize them but I'm guessing you didn't put the "
's around the password in?
他们真的需要吗?
这篇关于实体框架 - 基础提供程序在 ConnectionString 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架 - 基础提供程序在 ConnectionString 上失败
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01