Managing Connection Strings across Projects RRS feed

  • Question

  • I'm surprised that I haven't seen more posts on this issue, it makes me think i'm missing something obvious. There is a past post with the same Title as this one but the solution seems messy and unrealistic.

    We have a medium-large solution made up of around thirty projects, this is an oldish solution written using good old SqlConnection and a whole lot of using's. I'm in the process of converting it to EF. One problem I have is that I have to copy the connection string into an app config in *every* project, is there not an easy way for me to have one central store of connection string details to use with EF?



    Monday, October 22, 2012 7:10 AM

All replies

  • Hi,

    In most situations you can define the connection string only in the config file for the executing part of the code, the web.config or app.config of the app that is actually running when EF is used. If that makes sense.

    If you are in a situation where this doesn't work then you can use some of the other overloads of the DbContext constructor. One of them accepts a full connection string, you could read it from wherever you like, the other accepts a connection object that you create yourself. So with either of these two overloads you should be able to get a connection string from whatever location you like.

    You had to have connection strings for you current way of doing it right? So where are they at right now?

    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Monday, October 22, 2012 6:37 PM
  • At the moment they're in app and web configs dotted all over my solution - maybe it's a code structure issue, i have queries from libraries, queries from apps etc and they all have that same duplicated connection string - maintaining it is a pain
    Friday, November 2, 2012 1:49 PM