Hi Guys,
I have a class library that I've used as a DataAccessLayer in my website. In the web.config file for the website I defined a connectionstring.
In the class library I accessed the connectionstring like this:
However, today I tried creating a Windows project and referenced the dll. When I instantiate an instance of the class in the dll that references the connectionstring above I get a type initializer error "object instance not set to an instance of an object"
I know it's because it's a windows project and the dll is using the webconfiguartionmanager which is meant for asp.net.
My question is, how can I get the connectionstring in my class library based on the type of project it is referenced in. If I refrence the dll in a web project I need to use the WebConfigurationManager, and if I use it in a windows project I need to use the ConfigurationManager. Please advise
I have a class library that I've used as a DataAccessLayer in my website. In the web.config file for the website I defined a connectionstring.
In the class library I accessed the connectionstring like this:
Code:
Public Class MySchoolDataAccessLayer
Private Shared strCon As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("constr").ConnectionStringI know it's because it's a windows project and the dll is using the webconfiguartionmanager which is meant for asp.net.
My question is, how can I get the connectionstring in my class library based on the type of project it is referenced in. If I refrence the dll in a web project I need to use the WebConfigurationManager, and if I use it in a windows project I need to use the ConfigurationManager. Please advise