EnterpriseLibraryContainer is undefined in F# but DatabaseFactory.CreateDatabase() is ok

Topics: Data Access Application Block
Mar 13, 2012 at 9:53 AM
Edited Mar 13, 2012 at 9:53 AM

in VS2008 .net 3.5 ent 5.0 F# 2.0
EnterpriseLibraryContainer is undefined in F# but DatabaseFactory.CreateDatabase() is ok
let database = EnterpriseLibraryContainer.Current.GetInstance<Database>("FoodConnectionString")

what is the difference between both of them

<?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.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </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>
  <dataConfiguration defaultDatabase="FoodConnectionString" />
</configuration>

Mar 13, 2012 at 3:19 PM
Edited Mar 13, 2012 at 5:09 PM

I'm assuming you are getting a compilation error.

Do you have a reference added to Microsoft.Practices.EnterpriseLibrary.Common.dll?  You should.

Then you should be able to use:

let database =  
  Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.Current.GetInstance<Database>
    ("LocalSqlServer");

or

open Microsoft.Practices.EnterpriseLibrary.Common.Configuration
let database =  EnterpriseLibraryContainer.Current.GetInstance<Database>("FoodConnectionString");

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

Mar 14, 2012 at 8:55 AM
Edited Mar 14, 2012 at 8:56 AM

after added, open Microsoft.Practices.EnterpriseLibrary.Common.Configuration, it works