简体   繁体   中英

Entity Framework - The underlying provider failed on ConnectionString

While using the Entity Framework I have split it out to it's own project:

  • RivWorks.Model - Contains Entity Model
  • RivWorks.Controller - Uses the Entity Model and contains the biz rules
  • RivWorks.View.Web - The web site
  • RivWorks.View.Services - WCF project

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:

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?

Are they actually required?

Double check your connection string is correct, little typo's can cause this same error.

This is wrong:

 <add name="Entities" connectionString="metadata=res://*/OnlineAB.csdl|res://*/OnlineAB.ssdl|res://*/OnlineABSuperAdmin.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source.;initial catalog=

This is right:

 <add name="Entities" connectionString="metadata=res://*/OnlineAB.csdl|res://*/OnlineAB.ssdl|res://*/OnlineABSuperAdmin.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=

See after the DataSource I was missing an equal sign.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM