c# - How to use HTTPContext.Current.Session[].ToString to pass connection string to DB Context -


I am trying to pass the connection string in my DB reference and when I give it a fixed variable but my The requirement is to pass the connection string in the session variable how can I do it.

DB Reference

  Public EntEventServices_2_0Entities (string strConnectionString): base (strConnectionString) {}  

By starting the DB object, This works because it uses static variables:

  private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities (ConnectionManager.strConnectionString);  

But since now I have saved connectionstring in the sessionstring, so I am trying to do this:

  private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities (session ["ConnectionString"] .tar ());  

and this:

  private EntEventServices_2_0Entities db = new EntEventServices_2_0Entities (HttpContext.Current.Session ["ConnectionString"]. ToString ());  

But every time I'm getting the error:

An object reference is needed for non-static fields, methods, or property 'System.Web.Mvc .Controller A little detail about my application: I am developing an MVC5 application using EF 6 and requires that an application be connected to several databases of the same model.

Let me know that more information is needed.


Comments