Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Connection string in web.config
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00823105
Message ID:
00823132
Vues:
21
Chris,

>I am not using Mere Mortals.NET (yet!), but I am using the business object in the Hentzenwerke book. Right now, I have the database connection string hard-coded in the BusinessObject base class. Is it a better idea to put this in the web.config file? That seems to be what I am reading so far as best practices. If so, then should I set the connection string from web.config in the BusinessObject constructor method?

It is a better idea to put it in the web.config file, which is what we do in MM .NET. However, we wait until instantiating the data access object to retrieve the connection string from web.config. The reason for this, is that developers can store multiple connection strings in their config file which would be different for different types of data.

Here's some details:

1. Connection information is stored in the web.config file for Web apps and the app.config file for Windows Forms apps. A "databaes key" is stored along with the connection information to identify the database to which the connection belongs. One entry is created for each database accessed from the application.

2. At run time, the data access object is instantiated when the first request for data is made (JIT instantiation)

2. When the data access object instantiates, a call is made to the Database Manager's GetConnectionString method, passing the database "key" (a string used to identify a particular database).

3. If a connection for this database key hasn't been requested before, the Database Manager reads the config file to retrieve it, then caches this information in its connection collection for subsequent requests

Hope this helps!
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform