.net - Configuration question: sharing connection string for modules in app.config best practice -


I have [app | Web] .config and connection string declared in assembly (for example DAL and Reporting), which is dependent on the connection string What is the best thing for you to configure such assemblies:

  • [app | Use the string string name that worked hard in the web]. In the Config Connection Streams section, get the assembly back to its configuration by a hard-coded name. Therefore, there will probably be two similar connection strings: "Reporting Server" and "Datasource"

  • Use the connection section only with any name in the connection string which you prefer And configure DAL; Reporting of assemblies to use this name through custom configuration sections . Now assemblies use connection string to name and then retrieve connection string data.

  • Configure the connection string name via the app settings hard-code key . For example, you always have the "Reporting Server Connection String Name" & amp; In this case "dataSourceConnectionStringName" keys.

  • Something better than anything I was missed ...

Thank you in advance!

There are two ways to handle connection strings. The first way is by the way, The point is listed in.

The advantages are:

  • It's easy
  • If the conference uses the same name of the connection string, you can reuse

The disadvantages are:

  • The name is fixed
  • If you do not want the same connection for the same name, you are stuck then - Although overriding / add & amp; Removing the elements can help in this matter, but I have not tested it

The other technique I have used is ASP.NET The provider used by membership is similar to the model, etc.

   & Lt; / Providers & gt; & Lt; / Subscription & gt; & Lt; /system.web> & Lt; / Configuration & gt;  

The advantages are:

  • You can reuse the connection string in many components
  • The connection string name in your assemblies

The disadvantages are:

  • Too many tasks to install - Sometimes a small project overkill for
  • From configuration sections and providers (how not a bad thing, they are sometimes useful) Up need to understand
  • configuration file can be much more verbose.

Comments