I want to keep the Data access layer in a different class library project, but how can I manage Web.Config file ?
-
Hi, I want to encapsulate the Data Access Layer in a class library project where the class library will contain LINQ to SQL classes and Business Logic Layer. For my ASP.NET Web application, I will add that class library reference so that the ASP.NET Web application just behave like the Presentation Layer. I am highly tempted to implement this architecture. But I just got one challenge. As the Data Access Layer will maintain the Connection String of the SQL database in Web.Config file, when I reference that class library DLL to my ASP.NET Web Application, how will the Web.Config file of that class library project get integrated to my web.config file of the presentation ASP.NET Web Application ? At this moment, I am using ASP.NET 4.0 which has a cool feature : Web.Config.Debug, Web.Config.Release, so I can place the connection string of my production server website at Web.Config.Release. But, now, looks like, I will have to miss that feature as I am not sure how Web.Config (or App.Config) file will behave in my Data Access Layer class library project. Would you please give me some idea ?
-
Hi, I want to encapsulate the Data Access Layer in a class library project where the class library will contain LINQ to SQL classes and Business Logic Layer. For my ASP.NET Web application, I will add that class library reference so that the ASP.NET Web application just behave like the Presentation Layer. I am highly tempted to implement this architecture. But I just got one challenge. As the Data Access Layer will maintain the Connection String of the SQL database in Web.Config file, when I reference that class library DLL to my ASP.NET Web Application, how will the Web.Config file of that class library project get integrated to my web.config file of the presentation ASP.NET Web Application ? At this moment, I am using ASP.NET 4.0 which has a cool feature : Web.Config.Debug, Web.Config.Release, so I can place the connection string of my production server website at Web.Config.Release. But, now, looks like, I will have to miss that feature as I am not sure how Web.Config (or App.Config) file will behave in my Data Access Layer class library project. Would you please give me some idea ?
hi, You will get code samples from links below. http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx#Y570[^] and http://forums.asp.net/p/1038064/1438608.aspx#1438608[^] All you need to do is add System.Web in your DAL and you can read connection string property from web project, using
ConfigurationManager.ConnectionStrings
-
hi, You will get code samples from links below. http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx#Y570[^] and http://forums.asp.net/p/1038064/1438608.aspx#1438608[^] All you need to do is add System.Web in your DAL and you can read connection string property from web project, using
ConfigurationManager.ConnectionStrings
Hello, Thanks for your reply. I understood how to read connection string from my DAL. But, the DAL class library will be compiled to a single DLL file which can be added as a reference to my Presentation Web Application, how can I import that config file to my Presentation Web Application where the Presentation Web Application already contains Web.Config file. Wont that conflict ? Moreover, when the DAL assembly is added to the Presentation layer Web App, will my DAL DLL know that what is the config file it must read from ?
-
Hello, Thanks for your reply. I understood how to read connection string from my DAL. But, the DAL class library will be compiled to a single DLL file which can be added as a reference to my Presentation Web Application, how can I import that config file to my Presentation Web Application where the Presentation Web Application already contains Web.Config file. Wont that conflict ? Moreover, when the DAL assembly is added to the Presentation layer Web App, will my DAL DLL know that what is the config file it must read from ?
Any assemblies used in your application will use the configuration file from the main executable, unless otherwise specified. Copy the settings necessary for your data access layer to the web.config file.
I know the language. I've read a book. - _Madmatt