Activation error in F#

Topics: Data Access Application Block
Mar 12, 2012 at 7:52 AM

error 1

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

let database = DatabaseFactory.CreateDatabase()

error 2

EnterpriseLibraryContainer is not defined

let database = EnterpriseLibraryContainer.Current.GetInstance<Database>("ProjectListConnectionString");

Mar 12, 2012 at 8:20 AM

Do you have a configuration file?  I created a sample F# Console Application targeting  .NET Framework 4 (not Client Profile) and it seems to work.  

I added the following references:

Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.Configuration.dll
Microsoft.Practices.Unity.dll
Microsoft.Practices.Unity.Interception.Configuration.dll
Microsoft.Practices.Unity.Interception.dll

With the following app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <dataConfiguration defaultDatabase="LocalSqlServer" />
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>

Then the following F# code:

open System
open Microsoft.Practices.EnterpriseLibrary.Common.Configuration
open Microsoft.Practices.EnterpriseLibrary.Data

let database = DatabaseFactory.CreateDatabase()
Console.WriteLine(database.ConnectionString)

let database2 = EnterpriseLibraryContainer.Current.GetInstance("LocalSqlServer");
Console.WriteLine(database2.ConnectionString)

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Mar 12, 2012 at 8:30 AM

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="FoodConnectionString" connectionString="Data Source=PC29830\SQLEXPRESS;Initial Catalog=Food;Integrated Security=SSPI;Connect Timeout=60;MultipleActiveResultSets=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Mar 12, 2012 at 8:30 AM

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="FoodConnectionString" connectionString="Data Source=PC29830\SQLEXPRESS;Initial Catalog=Food;Integrated Security=SSPI;Connect Timeout=60;MultipleActiveResultSets=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Mar 12, 2012 at 8:49 AM

Success after add

<configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>