本文介绍了实体框架 - 基础提供程序在 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)

我有点困惑,为什么并仔细研究错误日志,我终于发现连接字符串没有从网站的配置文件中读取.所以,我添加了一些代码来捕捉它,现在,硬编码了这些值.喜欢:

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 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-25 09:08