views:

1369

answers:

1

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?

+1  A: 

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?

Alex James
EntityFramework stores its connection strings something like that, although mine have `"` from `provider connection string=` which could be where Keith's going wrong: `metadata=res://*/Models.DoodleEF.csdl|res://*/Models.DoodleEF.ssdl|res://*/Models.DoodleEF.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SqlExpress;Initial Catalog=zhpCoreContent;Integrated Security=True;MultipleActiveResultSets=True""`
Zhaph - Ben Duguid
They are copied straight out of the App.Config. I did the same thing for web.config - but wait - hard coded does not understand ". <doh/>. Will give that a shot in the morning.
Keith Barrows
Man, I wish I had another developer here who can look at code and see the simple mistakes buried inside of a string. Thanks guys! I replaced " with string quotes and the Context now builds. Off to the next error.
Keith Barrows
Yeah I hear yah... it is sooooo easy to overlook things by yourself.
Alex James