It depends a bit on how far you want to take this. In a pure solution, your person class wouldn't know about the database or connection string at all. It could call a method in the Data Access Layer that performs the save operation. This allows you to create a Business Layer (where the Person lives) that can be reused in multiple applications and multiple databases. The Database Layer in turn can deal with a specific database.
Anyway, even if you abstract away the data access from your business object, your question still applies to the Data Access Layer. There are still a couple of ways to do it:
One is to create a static connection string property on your DAL class. On start up of the application (for example, Application_Start in Web, Form_Load in Windows forms), you retrieve the connection string from the appropriate config file and assign it to the connection string property.
Another possibility is to create your own configuration file handler that can read Web.config and Application.config files. With a switch between Web and Config you can have the same class read multiple type of files. Take a look here (Google's cached version, as the original server could not be found): 220.127.116.11/search?q=cache:a7rY0PpP58MJ:http://www.eggheadcafe.com/articles/...onfigDoc&hl=en
(I left out http:// before 18.104.22.168 to partly fool the automatic linker that messes up these type of links)
Bottom line is: The easiest way to do is is probably a static property on the class that performs the database actions. When the application loads, you retrieve the connection string from the appropriate location, and assign it to the static property where it will stay for as long as the application lives.
I am sure there are many more possibilities, so I hope other people contribute to this thread as well.
Everyone is unique, except for me.
While typing this post, I was listening to: Swallow
(Track 10 from the album: Placebo
) What's This?