title: How to use HTTPContext.Current.Session[].ToString to pass connection string to DB Context
body: <p>I am trying to pass connection string to my DB Context and it worked when I pass a static variable to it. But my requirement is to pass the connection string in session variable. How can I do that. </p>
  
  <p>Below is the code and the different options I have used</p>
  
  <p>DB Context</p>
  
  <pre><code>public EntEventServices_2_0Entities(string strConnectionString)
          : base(strConnectionString)
      {
      }
  </code></pre>
  
  <p>Initiating db object, this worked since it used static variable:</p>
  
  <pre><code>private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities(ConnectionManager.strConnectionString);
  </code></pre>
  
  <p>But now since I have saved the connectionstring in session variable therefore I am trying to this:</p>
  
  <pre><code>private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities(Session["ConnectionString"].ToString());
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities(HttpContext.Current.Session["ConnectionString"].ToString());
  </code></pre>
  
  <p>But everytime I am getting following error:</p>
  
  <p>An object reference is required for the non-static field, method, or property 'System.Web.Mvc.Controller.HttpContext.get'</p>
  
  <p>A bit detail about my application: I am developing an MVC5 application using EF6 and the requirement is to have one application connect to multiple databases of similar model.</p>
  
  <p>Let me know if more details are required.</p>