1

I added an ADO.NET Entity Data Model to my project, which created a connection string in app.config looking like this:

<add name="KeyTranslatorEntities" connectionString="metadata=res://*/DAL.Model.csdl|res://*/DAL.Model.ssdl|res://*/DAL.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ZZZZZ.database.windows.net,1433;initial catalog=KeyTranslator;persist security info=True;user id=YYYYY;password=XXXXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

It also generated the class KeyTranslatorEntities which inherits from DbContext and has this default constructor:

public KeyTranslatorEntities()
        : base("name=KeyTranslatorEntities")
    {
    }

I create a KeyTranslatorEntities using the default generated constructor but upon inspection, the instance uses the connection string:

"data source=localhost;initial catalog=KeyTranslator;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

Why is it not using the correct connection string?

2
  • How did you check the connection string in use? Commented Jun 12, 2013 at 9:18
  • I set a breakpoint just before the program was crashing and inspected the DbContext object using debugmode Commented Jul 29, 2013 at 15:18

1 Answer 1

1

The problem was that the solution consisted of two different projects. One containing the EntityFramework code and another which was a WebService project with a dependency on the other project. The WebService project contained the first connection string which was being used.

Lesson learned: Make sure the startup project's config files are updated.

Sign up to request clarification or add additional context in comments.

3 Comments

How exactly did you get it to work? I'm able to pass a connection name, and when its wrong I get an error. But it still uses the default connection string (based on the Context class name). Very weird
My problem was that the default connection string was defined in two projects. I was looking at (and changing) the connection string from one project while it was using connection strings from the other, hence the confusion.
i heard that the default connection string (based on the context's class name) has a higher preference before explicitly named ones. Weird.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.