Last post Dec 21, 2011 05:56 PM by raringsunny
Nov 29, 2011 09:13 PM|raringsunny|LINK
I am working on an ASP.Net website where I have used the layered architecture approach.
I have a separate layer for Data Access, Business logic, Presentation etc.
I get the following error when trying to use Enterprise Library Data Access app block.
The type Database cannot be constructed. You must configure the container to supply this value.
After researching on net, I found out that to fix the problem the connection string needs to be supplied to the CreateDatabase class construcor as shown in the statement below.
Database db = DatabaseFactory.CreateDatabase("<Connection
string from config file>");
The afore-mentioned code would typically be part of Data access layer (which is a separate class library project).
How the Data access layer should read the configuration information being a class library project? Usually, the web.config file exists in the Web application project.
Should we have an app.config file in the Data access library project or which other way configuration information (connection string) can be read from a config file from a data access library project?
data access layer
Nov 29, 2011 11:25 PM|prasadP|LINK
The class library project's dll can access the web.config in the web application it is used.
Nov 30, 2011 12:20 AM|hemant.yadav|LINK
Do the following setting into ConfigSection
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=220.127.116.11, Culture=neutral, PublicKeyToken=null"/>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=18.104.22.168, Culture=neutral, PublicKeyToken=null"/>
<add name="ConnectionString" connectionString="Yuur Connection String" providerName="System.Data.SqlClient"/>
Dec 21, 2011 05:56 PM|raringsunny|LINK
To close this thread, I would like to mention here what solved the issue for me.
As Hemant copied the configuration above, the following statement was missing from my web.config where the default database needs to be specified. The
method takes the following configuration into consideration in its constructor if no config varible or connection string is specified.
Please point out if my understanding is incorrect. I had resolved this issue sometime back. From what I remember is this and I thought of sharing the same here in the forum.