The type Database cannot be constructed. You must configure the container to supply this value.

Topics: Data Access Application Block
Aug 4, 2011 at 11:44 PM

I am getting this error on the test server after deploying an app I am building. It works fine on my Win 7 Dev machine in VS2010. On a lark I installed VS2010 Express on the test server and ran the app in debug and View in Browser modes and it works as it should. However when hitting it through IIS, it throws this error.

Test server is Win 2008R2, .Net 4.0, Oracle ODP.NET provider. Connection Strings from web.config:

<connectionStrings>
	<add name="OraAspNetConString" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.36)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ora10)));User Id=web;Password=web;" providerName="Oracle.DataAccess.Client" />
</connectionStrings>

Error Report:

The type Database cannot be constructed. You must configure the container to supply this value.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.

Source Error:

Line 293:#Region "LMControl Methods"
Line 294: Public Shared Function GetLMControl() As IDataReader
Line 295: Dim OracleDB As Database = EnterpriseLibraryContainer.Current.GetInstance(Of Database)("OraAspNetConString")
Line 296:
Line 297: Dim sb As New StringBuilder()


Source File: C:\inetpub\records\App_Code\DAL\DataProvider.vb Line: 295

Stack Trace:

[InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.]
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:289
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:71
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:112
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlanCreatorPolicy.cs:50
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:37
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:112
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:511

[ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "OraAspNetConString".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.


At the time of the exception, the container was:

Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,OraAspNetConString
]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:517
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:485
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:49

[ActivationException: Activation error occured while trying to get instance of type Database, key "OraAspNetConString"]
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:57
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:103
DataProvider.GetLMControl() in C:\inetpub\records\App_Code\DAL\DataProvider.vb:295
LMControlController.GetLMControl() in C:\inetpub\records\App_Code\BLL\LMControlCtrl.vb:12
subscription_Default.Page_Load(Object sender, EventArgs e) in C:\inetpub\records\subscription\Default.aspx.vb:11
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048 


Aug 5, 2011 at 1:01 AM

Hi KentWa,

There must be something wrong in the connection string, assuming you correctly reference  all the assembly you needed then that should work in IIS. 

Aug 8, 2011 at 9:33 PM

Hi KentWA

Have you found any solution to that problem?

I´m having exactly the same problem when deploying the application

Anyone has an idea?

Aug 9, 2011 at 5:52 AM

No Solution as of yet. Since the Dev machine and the test machine use the same DB and very same web.config I have to make the assumption that there is nothing wrong with the connection string. There are a ton of simular queries using a google search, but no resolutions that work for me.

Aug 9, 2011 at 6:18 AM

Hi,

Have you added the necessary provider mappings to your configuration just like on this guide?

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 9, 2011 at 6:34 PM

That guide is a little difficult to fallow

Could anyone please complete or send a simple mapping file?

Default.aspx

<body>
    <form id="form1" runat="server">
    <div>
        <%--style="width: 100%;"--%>
        <table>
            <tr>
                <td>
                    <asp:Button ID="btnConsultaDirectoOracle" runat="server" OnClick="btnConsultaDirectoOracle_Click"
                        Text="Consulta Directo Oracle" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="gvDatos" runat="server">
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>

WEB.Config

 

<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <dataConfiguration defaultDatabase="SqlServer">
    </dataConfiguration>
    <connectionStrings>
        <!--Oracle 10g XE - Human Resourse Tables-->
        <add name="Oracle" connectionString="DATA SOURCE=192.168.0.186;PASSWORD=hr;USER ID=HR" providerName="Oracle.DataAccess.Client" />
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
</configuration>

provider mappings..........

Aug 9, 2011 at 10:24 PM

I completly solved this by switchiing to the System.Data.OracleClient Provider. I should have known since I have had nothing but grief out of getting Oracle to work under windows, this is just one more issue. I have not figured out why The Oracle.DataAccess.Client works on Dev and not test or deploy.

Aug 11, 2011 at 10:16 AM
Edited Aug 11, 2011 at 10:20 AM

Have you checked if you are using the same version of Oracle? What version of Oracle are you using? As far as I know, System.Data.OracleClient provider doesn't work on latest versions of Oracle.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 11, 2011 at 3:23 PM

Yes, the first thing I checked was that the Client version was the same one installed. This particular install version of Oracle is a 10g database.

Aug 12, 2011 at 3:44 AM

Do you have the same software specification (OS version, bit architecture, .NET Framework Version) on each machines? I'm not really familiar with ODP.NET but I guess you need to install the right version of ODP.NET for the corresponding software specs. Anyway, I'm glad to hear that you make it work! :)

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Mar 15, 2012 at 3:49 PM
Edited Mar 15, 2012 at 3:49 PM

You don't need to switch to MS Client.

Check out this link. It's a step-by-step tutorial and you can also download a sample.