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

后端 未结 13 1286
渐次进展
渐次进展 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:56

    Roll your own ConnectionFactory based on .config files:

    • Define a custom config section to map key/connectionstring pairs
    • Teach your ConnectionFactory to sniff into that config section using hostname or machinename as appropriate
    • Populate key/connectionstring values for your various dev/qa/prod servers, and drop them into your various app.config, web.config etc. files.

    Pro:

    • All lives inside the project, so no surprises
    • Adding additional deployment target is a copy/paste operation in a .config file

    Con:

    • Makes for big ugly XML sections, especially if you have a dozen production servers
    • Needs to be duplicated between projects
    • Needs code change & redeploy to add new target
    • Code needs to know about the environment in which it will live

提交回复
热议问题