none
Why connection string in web.config file?? RRS feed

  • Question

  • As far as i know we create a connection between the Database and web application using web.config file by providing a connection string.

    The reasons why we do so ?

    1. This is non compiled file. justify ? why we need this non compiled file ?

    2. Cannot open web.config in the browser: This i undesrtand, for the security reason.

    I need the justification for the "1" point.

    Thanks..

     
    Sunday, February 19, 2012 7:43 AM

Answers

  • I assume we put it web.config file such that later if changes comes we need not rebuild/recompile the application in case there are changes to say server or database or authetication.

    If the connection string was in code then we would need to rebuild/ deploy the .dll again to the server whereas now it would jus be a case of replacing the config file.

    Same applies even for key value pairs, in effect Web.config is same as app.config for Windows applications, it stores the configuration for the web applications.

    Thats precisley the reason whey can have multiple web.config files inside a web app, so that we can configure/ override the default configurations which are laoded via the machine.config file on the server.


    Abhinav

    • Marked as answer by rdddddddd Monday, February 20, 2012 11:58 AM
    Monday, February 20, 2012 5:09 AM

All replies

  • I assume we put it web.config file such that later if changes comes we need not rebuild/recompile the application in case there are changes to say server or database or authetication.

    If the connection string was in code then we would need to rebuild/ deploy the .dll again to the server whereas now it would jus be a case of replacing the config file.

    Same applies even for key value pairs, in effect Web.config is same as app.config for Windows applications, it stores the configuration for the web applications.

    Thats precisley the reason whey can have multiple web.config files inside a web app, so that we can configure/ override the default configurations which are laoded via the machine.config file on the server.


    Abhinav

    • Marked as answer by rdddddddd Monday, February 20, 2012 11:58 AM
    Monday, February 20, 2012 5:09 AM
  • Most people are not testing against the production database, real profesional organizations have mostly a 

    - Development database
    - Test database
    - Authorizationverifiying database
    - Production database

    So not clever to put that in the program direct, as the developer has no access to the 3 (or more) later ones.


    Success
    Cor

    Monday, February 20, 2012 8:18 AM
  • Thanks i got it now :))
    Monday, February 20, 2012 11:58 AM