Gustavo Melo
Gustavo Melo

Reputation: 199

Enterprise Library Migration - You must configure the container to supply this value

I don't know who else to ask for help.

Here in my company we are migrating the system. 2.0 to 3.5 net

We use enterprise library 3.1 and we are migrating to 5.0

I used the tool for configuration file

The compilation was ok but when I run, i receive this message:

Activation error occured while trying to get instance of type Database, key "MrvFramework"

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "MrvFramework". 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

I spent a lot of time on internet:

I had made this tests:

This is my app.config (snippet-code)

<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" />

<dataConfiguration defaultDatabase="MRVFramework"/>
<connectionStrings>
   <add name="MRVFramework" connectionString="Data Source=H:\MRV\Projetos\MRV Framework\Branch\Update SqlServerCe\MRV.Framework.Seguranca.Console\MRVFramework.sdf;Persist Security Info=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

This is my machine.config file

<DbProviderFactories>
  <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>

Upvotes: 4

Views: 4465

Answers (2)

Neeraj Singh Chouhan
Neeraj Singh Chouhan

Reputation: 676

Add this Code to your web.config

<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Data" fullName="Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   </assemblyBinding>
</runtime>

Upvotes: 1

Muru Bakthavachalam
Muru Bakthavachalam

Reputation: 1350

I was getting same exception while executing the below code;

Database db = DatabaseFactory.CreateDatabase();

Resolved exception once i updated the code to

Database db = DatabaseFactory.CreateDatabase("Connection String"); // config file string

Upvotes: 0

Related Questions