Connection string hell in .NET / LINQ-SQL / ASP.NET

后端 未结 13 1129
渐次进展
渐次进展 2021-01-30 14:29

I have a web application that comprises the following:

  • A web project (with a web.config file containing a connection string - but no data access code in the web pr
13条回答
  •  再見小時候
    2021-01-30 14:58

    Roll your own ConnectionFactory based on the Registry:

    • add a registry key for your application under SOFTWARE/[YOUR_COMPANY]/[YOUR_APP]
    • add a string value for ConnectionString
    • Teach your ConnectionFactory to crack open the appropriate registry key (in a static constructor, not every page load!).
    • export the registry info as a .reg file, add it to source control, modify and apply it as necessary to set up additional machines.

    Pro:

    • Simple to set up
    • Connectionstring lives in a single place
    • Not in web/app.config, so no need to hardcode environment-specific settings.
    • Not in web/app.config, so Junior Dev Jimmy can't accidentally tell your production server to look at the DEV database

    Con:

    • Not immediately obvious that important things are living in the registry, so new devs will need instructions.
    • Extra step when configuring a new deployment machine
    • Registry is oldskool. Junior devs will mock you.

提交回复
热议问题