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?
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
DatabaseFactory.CreateDatabase()
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.
raringsunny
Member
133 Points
109 Posts
Using Enterprise Library from Data Access Layer
Nov 30, 2011 01:13 AM|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?
Thanks!
enterprise lib. data access layer daab design dal
prasadP
Contributor
5266 Points
771 Posts
Re: Using Enterprise Library from Data Access Layer
Nov 30, 2011 03:25 AM|LINK
Hi Friend,
The class library project's dll can access the web.config in the web application it is used.
Use ConfigurationManager.ConnectionStrings.
http://forums.asp.net/t/1394239.aspx/1
Blog
hemant.yadav
Contributor
2261 Points
682 Posts
Re: Using Enterprise Library from Data Access Layer
Nov 30, 2011 04:20 AM|LINK
Do the following setting into ConfigSection
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null"/>
<dataConfiguration defaultDatabase="ConnectionString"/>
<connectionStrings>
<add name="ConnectionString" connectionString="Yuur Connection String" providerName="System.Data.SqlClient"/>
</connectionStrings>
Please remember to click “Mark as Answer” on the post that helps you
raringsunny
Member
133 Points
109 Posts
Re: Using Enterprise Library from Data Access Layer
Dec 21, 2011 09:56 PM|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 DatabaseFactory.CreateDatabase() method takes the following configuration into consideration in its constructor if no config varible or connection string is specified.
<dataConfiguration defaultDatabase="ConnectionString"/>
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.
--raringsunny