2

We have to reference an EF connection string in a couple of places in a solution.

In our EF DataContext project its contained in the App.Config.

And in the WebApi project its contained in the Web.Config.

Now, from googling I can use 'add as link' to reference an App.config from another project, however, I (at least dont think I can) do this with the WebApi link being in the web.config.

As the devs are all using a local instance of the database currently and so with each push we are manually having to change in each location (i know its only a couple but still a bit of a pain).

If there any way we can pul it out to a single location? and also coul dwe maybe setup some kind of switch so I it will use the right string in each environment.

Thanks in advance.

Matthew Flynn
  • 3,661
  • 7
  • 40
  • 98

2 Answers2

0

If App.config is pointing to a local instance it is probably not an issue, as long as the database name and SQL Server instance name are the same on each developer's machine by agreement. The same holds for the connection string in Web.config. Having two connection strings in two projects is all right.

Martin Staufcik
  • 8,295
  • 4
  • 44
  • 63
0

You could explicitly set it in code, taking the value from some config store. Then reference that library from all your projects.

See the answer to this question: How do I programmatically set the connection string for Entity-Framework Code-First?

Community
  • 1
  • 1
Rob Potter
  • 948
  • 6
  • 28