Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Getting ConnectionStrings from Web.xml file - XML being parsed each time??

Getting ConnectionStrings from Web.xml file - XML being parsed each time??

Scheduled Pinned Locked Moved ASP.NET
visual-studioxmlperformancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dominic Pettifer
    wrote on last edited by
    #1

    I'm just curious when I grab a connection string from my Web.config file using, say, WebConfigurationManager... // Dont have my VS2005 IDE so code may be incorrect string connectionString = WebConfigurationManager.ConnectionStrings["myDatabase"]; ...is the xml from the web.config file being read and parsed each and everytime this method is called? Or does is load the web.config and all it's settings into memory? If it is reading the file each time, would it be faster to place the connection string into the Application Cache and read it from there? Cheers!

    Sunday Ironfoot www.dominicpettifer.co.uk (work in progress)

    K 1 Reply Last reply
    0
    • D Dominic Pettifer

      I'm just curious when I grab a connection string from my Web.config file using, say, WebConfigurationManager... // Dont have my VS2005 IDE so code may be incorrect string connectionString = WebConfigurationManager.ConnectionStrings["myDatabase"]; ...is the xml from the web.config file being read and parsed each and everytime this method is called? Or does is load the web.config and all it's settings into memory? If it is reading the file each time, would it be faster to place the connection string into the Application Cache and read it from there? Cheers!

      Sunday Ironfoot www.dominicpettifer.co.uk (work in progress)

      K Offline
      K Offline
      kiran kumar Intelligroup
      wrote on last edited by
      #2

      Yes you are right,web.config is parsed each and everytime and your method will be called.This will show impact on performance so you can use cache memory to hold the connecton string. Dont forget to set the expiry policy for that cache item, i prefer file based expiry policy so that when web.config is changed then cache item get refreshed.

      D 1 Reply Last reply
      0
      • K kiran kumar Intelligroup

        Yes you are right,web.config is parsed each and everytime and your method will be called.This will show impact on performance so you can use cache memory to hold the connecton string. Dont forget to set the expiry policy for that cache item, i prefer file based expiry policy so that when web.config is changed then cache item get refreshed.

        D Offline
        D Offline
        Dominic Pettifer
        wrote on last edited by
        #3

        Interesting, if it is parsing the xml file each time it's doing it really quickly, far more efficiently than I thought. For instance if I do something like the follow code...

        for (int i = 0; i < 1000; i++)
        {
           connectionString = 
              WebConfigurationManager.ConnectionStrings["default"].ConnectionString;
        }
        

        ...it's going to parse the xml file 1000 times and cause the page execution to hang for a bit, except my page execution time is about 0.015 seconds. Also if I add a Thread.Sleep(1) inside the for loop the page execution jumps to about 2 seconds (1 second for Thread.Sleep(1) x 1000 plus any overhead from Thread.Sleep() method) meaning it's not my page timer thats not timing properly or anything. Are you sure it's reading the web.config file each time and not just reading the settings from memory? Or have I way overestimated the overhead of parsing through xml?

        Sunday Ironfoot www.dominicpettifer.co.uk (work in progress)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups