3

Using .net 3.5 and Enterprise library 5.0.

From my research, I found a similar issue here: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" *** this solution did not fix my issue.

I can't seem to figure it out, my config should be set up correctly, but keep getting the exception? Anyone have similar issues?

I made the suggestion to add cacheManager and reference when I call the cache manager:

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
.....
....
ICacheManager cm = CacheFactory.GetCacheManager("TrackingCacheManager");

The App.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" />
        <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
     <cachingConfiguration defaultCacheManager="TrackingCacheManager">
        <cacheManagers>
            <add name="TrackingCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                expirationPollFrequencyInSeconds="120" maximumElementsInCacheBeforeScavenging="1000"
                numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
        </cacheManagers>
        <backingStores>
            <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="NullBackingStore" />
        </backingStores>
    </cachingConfiguration>
    <dataConfiguration defaultDatabase="ConnectionString" />
    <connectionStrings>
        <add name="ConnectionString" connectionString="server=AFS7BCBRNGQ5O0\DEVELOPMENT;database=EITC_RTS;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

My references:

enter image description here

Community
  • 1
  • 1
Chaka
  • 1,709
  • 11
  • 33
  • 58
  • Make sure full config references trace listeners are defined in the App.config. For details check this - http://stackoverflow.com/questions/7813925/activation-error-occured-while-trying-to-get-instance-of-type-logwriter-key – Systematix Infotech Jun 05 '14 at 04:57
  • The example related to logging, would I need a listener for the data access block? – Chaka Jun 05 '14 at 11:37
  • Have you tried removing the `PublicKeyToken` from the configuration? You may have DLLs with different tokens and when they don't match up, you get exceptions. – gfish3000 Jun 10 '14 at 15:39
  • do you get the same result if you do not specify the Cache name when invoking GetCacheManager()? – dblood Jun 11 '14 at 13:28

2 Answers2

4

My guess is that you've setup this configuration in an App.config for your Domain project. But your main project has it's own config file which this configuration must be copied into.

So for example, if your main project was a webapp, then it would have a web.config. The caching configuration you have added to the App.config of the Domain project is not used at runtime. The configuration being used is from main project's config, in this example the web.config.

Copy your Caching configuration from the Domain App.Config to the main config file and it will work.

dblood
  • 1,758
  • 17
  • 21
0

I have done silly mistake, but after read above, understand the issue. This is my vb.net code which give me the above error.

Imports System.Collections
'Imports System.Configuration

Public Class DatabaseLogic
    Public ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("db").ToString()

    Public Function ServerDataMagic(StoredProcedure As String, PDMdata As Hashtable) As DataSet
        Dim db As Database = DatabaseFactory.CreateDatabase(ConnectionString )  'Here  I am getting error.
        Using cmd As DbCommand = db.GetStoredProcCommand(StoredProcedure)
            Try
                db.DiscoverParameters(cmd)
            Catch discover_ex As Exception

            End Try

and in web.config entry is

<add name="db" connectionString="Database=Dbname;Server=SERVER;uid=sa;pwd=sa@1234" providerName="System.Data.SqlClient" />

After read just get the issue is CreateDatabase method wants a config entry key as a string and I was given the exact connection string via config entry access. This is my updated code.

  Dim db As Database = DatabaseFactory.CreateDatabase("db")  'Here I changed the config entry key

I was post to somebody help.

Ajay2707
  • 5,690
  • 6
  • 40
  • 58