Quantcast
Channel: patterns & practices – Enterprise Library
Viewing all 1928 articles
Browse latest View live

Commented Unassigned: Memory leak upgrading Enterprise Library from 3.1 to 6.0 [33834]

$
0
0
Hello,

I'm using the data access block from Enterprise Library which was upgraded from version 3.1 to 6.0.
With the upgrade, I had to make some changes to create a new DatabaseProviderFactory each time our class is instantiated in the constructor method as follows:

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
DatabaseProviderFactory providersFactory = new DatabaseProviderFactory(configurationSource);
DatabaseFactory.SetDatabaseProviderFactory(providersFactory, false);


I've made sure to wrap all the Command objects with the "using" statement, but still I am seeing a memory leak.

Has anyone experienced this issue? I would appreciate any help!

Thanks in advance.

Comments: You don't __need__ to make your class a singleton. You should just load the configuration once (assuming that you only want to load the configuration once). ``` c# public class MyClass { static MyClass() { IConfigurationSource configurationSource = ConfigurationSourceFactory.Create(); DatabaseProviderFactory providersFactory = new DatabaseProviderFactory(configurationSource); DatabaseFactory.SetDatabaseProviderFactory(providersFactory, false); } private Database DB { get; set; } public MyClass(string dbName) { DB = DatabaseFactory.CreateDatabase(dbName); } public void ExecuteMyQuery() { DB.ExecuteNonQuery(...); } } ``` I'm not sure what your code looks like so the above is just something I typed up. Notice that the code loads the configuration once in a static constructor and then uses the static DAAB methods to retrieve a database instance.

Commented Unassigned: Memory leak upgrading Enterprise Library from 3.1 to 6.0 [33834]

$
0
0
Hello,

I'm using the data access block from Enterprise Library which was upgraded from version 3.1 to 6.0.
With the upgrade, I had to make some changes to create a new DatabaseProviderFactory each time our class is instantiated in the constructor method as follows:

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
DatabaseProviderFactory providersFactory = new DatabaseProviderFactory(configurationSource);
DatabaseFactory.SetDatabaseProviderFactory(providersFactory, false);


I've made sure to wrap all the Command objects with the "using" statement, but still I am seeing a memory leak.

Has anyone experienced this issue? I would appreciate any help!

Thanks in advance.

Comments: Thank you very much for the code snippet. I will try this!

Created Unassigned: Upgrading Enterprise Library Logging from version 3.1 to 6.0, Logger.Writer.Dispose() no longer closes the flat file [33835]

$
0
0
Hello,

Our application uses the Enterprise Library logging version 3.1 to write to a flat file log. We called Logger.Writer.Dispose(); after doing a Logger.Write every time which allows for us to delete or access the flat file while the application is still running.

After upgrading to version 6.0, we can no longer delete or access the flat file without first shutting the application down.

What do we need to do in order to close or release the lock on the flat file after each write to the file?

Thanks in advance!


Commented Unassigned: Upgrading Enterprise Library Logging from version 3.1 to 6.0, Logger.Writer.Dispose() no longer closes the flat file [33835]

$
0
0
Hello,

Our application uses the Enterprise Library logging version 3.1 to write to a flat file log. We called Logger.Writer.Dispose(); after doing a Logger.Write every time which allows for us to delete or access the flat file while the application is still running.

After upgrading to version 6.0, we can no longer delete or access the flat file without first shutting the application down.

What do we need to do in order to close or release the lock on the flat file after each write to the file?

Thanks in advance!


Comments: Can you post a complete example that recreates the behavior at the Logging Application Block discussion forum: http://lab.codeplex.com/discussions "Issues" should be used for work items and bugs. Thanks. In my experience, Disposing the Writer releases the locks. Note that Dispose is not thread-safe so if you are disposing while other threads are logging it could cause issues. Also, opening and closing the file will be a performance hit. While it's true you can't delete the locked file, you can read through the lock and some editors will let you open the file while it's locked.

Commented Unassigned: Upgrading Enterprise Library Logging from version 3.1 to 6.0, Logger.Writer.Dispose() no longer closes the flat file [33835]

$
0
0
Hello,

Our application uses the Enterprise Library logging version 3.1 to write to a flat file log. We called Logger.Writer.Dispose(); after doing a Logger.Write every time which allows for us to delete or access the flat file while the application is still running.

After upgrading to version 6.0, we can no longer delete or access the flat file without first shutting the application down.

What do we need to do in order to close or release the lock on the flat file after each write to the file?

Thanks in advance!


Comments: I will repost on the discussion forum. Thanks!

New Post: GetInstance(anything) gives ActivationException when platform target set to x86

New Post: Specify multiple config file in enterpriseLibrary.ConfigurationSource

$
0
0
Hi Randy, Thanks for the response. I wanted to try this out however I don’t find this class or any reference in code,
MergeConfigurationSource mergConfigurationSource = new MergeConfigurationSource(myAppConfigurationSource, esbConfigurationSource);

Could you please help me locate the class?
If I could do this merging in my custom application and just leave the ESB as it this that would solve my problem.

New Post: Semantic Logging does not log the updated event source message in Out-Of-Process

$
0
0
I am using Semantic Logging Out-Of-Process in my application. I have created an eventsource class as shown below

[EventSource(Name = "SemanticLoggingOutOfProcessEventSource")]
public class SampleEventSource : EventSource
{
public class Keywords
{
    public const EventKeywords Page = (EventKeywords)1;
    public const EventKeywords DataBase = (EventKeywords)2;
    public const EventKeywords Diagnostic = (EventKeywords)4;
    public const EventKeywords Perf = (EventKeywords)8;
}

public class Opcodes
{
    public const EventOpcode Start = (EventOpcode)20;
    public const EventOpcode Finish = (EventOpcode)21;
    public const EventOpcode Error = (EventOpcode)22;
    public const EventOpcode Starting = (EventOpcode)23;

    public const EventOpcode QueryStart = (EventOpcode)24;
    public const EventOpcode QueryFinish = (EventOpcode)25;
    public const EventOpcode QueryNoResults = (EventOpcode)26;

    public const EventOpcode CacheQuery = (EventOpcode)27;
    public const EventOpcode CacheUpdate = (EventOpcode)28;
    public const EventOpcode CacheHit = (EventOpcode)29;
    public const EventOpcode CacheMiss = (EventOpcode)30;
}

public class Tasks
{
    public const EventTask Page = (EventTask)1;
    public const EventTask DBQuery = (EventTask)2;
    public const EventTask Application = (EventTask)3;            
}

[Event(1, Message = "Method1 Starting.", Opcode = Opcodes.Starting, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method1Starting() { if (this.IsEnabled()) this.WriteEvent(1); }

[Event(2, Message = "Method1 Ending.", Opcode = Opcodes.Finish, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method1Ending() { if (this.IsEnabled()) this.WriteEvent(2); }

[Event(3, Message = "Method2 Starting.", Opcode = Opcodes.Starting, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method2Starting() { if (this.IsEnabled()) this.WriteEvent(3); }

[Event(4, Message = "Method2 Ending.", Opcode = Opcodes.Finish, Task = Tasks.DBQuery, Level = EventLevel.Informational, Keywords = Keywords.Perf)]
public void Method2Ending() { if (this.IsEnabled()) this.WriteEvent(4); }

public static readonly SampleEventSource outOfProcessLog = new SampleEventSource();               
}

I set the eventsource name in the packages\EnterpriseLibrary.SemanticLogging.Service.2.0.1406.1\tools\SemanticLogging-svc.xml. I started the Semantic Service and ran the application. The log was written to the "packages\EnterpriseLibrary.SemanticLogging.Service.2.0.1406.1\tools\SemanticLogging-svc.runtime.log" file. I have the following issues:
  1. Whenever i make a change to the Message attribute ( suppose i change the "Method1 Starting." to "Method1 Started."). The log is written again as "Method1 Starting." instead of "Method1 Started.". Why? The only way i could achieve this is to stop the service and change the EventSource Name everytime there is an update to Message attribute, which is very painful. Is there any other way to achieve this without changing the EventSource name?
  2. Is it possible to log messages to any other log file instead of logging to SemanticLogging-svc.runtime.log?
  3. I could only create EventOpcode starting from 20. Wont i be able to start EventOpcodes from 1 similar to Tasks?
Please provide me the information asap which will help me achieve the output.

New Post: Specify multiple config file in enterpriseLibrary.ConfigurationSource

$
0
0
The MergeConfigurationSource code was in the post that I referenced.

Here's a slightly modified version of that code:
///<summary>/// Takes two <see cref="IConfigurationSource"/>s and tries to merge settings from both///</summary>publicclass MergeConfigurationSource : IConfigurationSource
    {
        #region Fields

        privatereadonly HierarchicalConfigurationSourceHandler hierarchicalConfigurationSourceHandler;
        privatereadonly CompositeConfigurationSourceHandler compositeConfigurationSourceHandler;
        privatereadonly IConfigurationSource parentSource;
        privatereadonly IConfigurationSource localSource;

        privatereadonlyobject eventHandlersLock;  // lock used to protect the event handlers listprivatereadonly EventHandlerList eventHandlers;

        #endregion Fields

        #region Constructor

        ///<summary>/// Initializes a new instance of the <see cref="MergeConfigurationSource"/> class.///</summary>///<param name="localSource">The local source.</param>///<param name="parentSource">The parent source.</param>///<remarks>Naming of the parameters uses Enterprise Library conventions /// (<seealso cref="hierarchicalConfigurationSourceHandler"/>)</remarks>public MergeConfigurationSource(IConfigurationSource localSource, IConfigurationSource parentSource)
        {
            if (localSource == null) thrownew ArgumentNullException("localSource");
            if (parentSource == null) thrownew ArgumentNullException("parentSource");

            this.localSource = localSource;
            this.parentSource = parentSource;

            this.localSource.SourceChanged += OnSourceChanged;
            this.parentSource.SourceChanged += OnSourceChanged;

            hierarchicalConfigurationSourceHandler = new HierarchicalConfigurationSourceHandler(this.localSource, this.parentSource);
            compositeConfigurationSourceHandler = new CompositeConfigurationSourceHandler(this.parentSource);

            eventHandlersLock = newobject();
            eventHandlers = new EventHandlerList();
        }

        #endregion Constructor

        ///<inheritdoc/>publicevent EventHandler<ConfigurationSourceChangedEventArgs> SourceChanged = delegate { };

        ///<inheritdoc/>publicvoid Dispose()
        {
            hierarchicalConfigurationSourceHandler.Dispose();
            compositeConfigurationSourceHandler.Dispose();

            parentSource.Dispose();
            localSource.Dispose();
        }

        ///<summary>/// Gets a section identified by its <paramref name="sectionName"/>. If the section exists in local and parent source it/// will be merged.///</summary>///<param name="sectionName">Name of the section.</param>///<returns>The configuration section with the given <paramref name="sectionName"/>; <c>null</c> if no such section can be found.</returns>public ConfigurationSection GetSection(string sectionName)
        {
            if (sectionName == null) thrownew ArgumentNullException("sectionName");

            ConfigurationSection configurationSection = localSource.GetSection(sectionName);

            configurationSection = compositeConfigurationSourceHandler.CheckGetSection(sectionName, configurationSection);

            return hierarchicalConfigurationSourceHandler.CheckGetSection(sectionName, configurationSection);
        }

        ///<summary>/// Adds the specified section to the local configuration source///</summary>///<param name="sectionName">Name of the section.</param>///<param name="configurationSection">The configuration section.</param>publicvoid Add(string sectionName, ConfigurationSection configurationSection)
        {
            if (sectionName == null) thrownew ArgumentNullException("sectionName");
            if (configurationSection == null) thrownew ArgumentNullException("configurationSection");

            if (!compositeConfigurationSourceHandler.CheckAddSection(sectionName, configurationSection))
            {
                try
                {
                    localSource.Add(sectionName, configurationSection);
                }
                catch (Exception innerException)
                {
                    var exception = new Exception("Failed to add section: " + sectionName, innerException);

                    throw exception;
                }
            }
        }

        ///<summary>/// Removes the specified section from parent and local configuration source///</summary>///<param name="sectionName">Name of the section to remove</param>publicvoid Remove(string sectionName)
        {
            if (sectionName == null) thrownew ArgumentNullException("sectionName");

            if (!compositeConfigurationSourceHandler.CheckRemoveSection(sectionName))
            {
                localSource.Remove(sectionName);
                parentSource.Remove(sectionName);
            }
        }

        ///<inheritdoc/>publicvoid AddSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
        {
            if (sectionName == null) thrownew ArgumentNullException("sectionName");
            if (handler == null) thrownew ArgumentNullException("handler");

            lock (eventHandlersLock)
            {
                eventHandlers.AddHandler(sectionName, handler);
            }
        }

        ///<inheritdoc/>publicvoid RemoveSectionChangeHandler(string sectionName, ConfigurationChangedEventHandler handler)
        {
            if (sectionName == null) thrownew ArgumentNullException("sectionName");
            if (handler == null) thrownew ArgumentNullException("handler");

            lock (eventHandlersLock)
            {
                eventHandlers.RemoveHandler(sectionName, handler);
            }
        }

        privatevoid OnSourceChanged(object sender, ConfigurationSourceChangedEventArgs e)
        {
            SourceChanged(this, e);
        }
    }
~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Semantic Logging does not log the updated event source message in Out-Of-Process

$
0
0
Item #1 sounds like a schema caching issue similar to this work item. The two workarounds posted on that work item are to delete the cahced provider info or to run the OOP service in console mode. Also, typically and

Is it possible to log messages to any other log file instead of logging to SemanticLogging-svc.runtime.log?

You can modify the SemanticLogging-svc.xml file (which is the default config file used by the OOP service) to write direct the events to another file (or another sink).

I could only create EventOpcode starting from 20. Wont i be able to start EventOpcodes from 1 similar to Tasks?

You should be able to create an Opcode with a lower value than 20. However, there are some reserved Opcodes. From the Developer's Guide:

If you choose to define custom opcodes, you should assign integer values of 11 or above, otherwise they will clash with the opcodes defined in the EventOpcode enumeration. If you define a custom opcode with a value of 10 or below, messages that use these opcodes will not be delivered.

If you try to use an Opcode of 10 or less you will receive an ArgumentException, "Opcode values less than 11 are reserved for system use". You can start using Opcodes at 11 and higher. Also, there is a built-in Opcode, Receive, with a value of 240; you can use it but the Opcode may display as Receive.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Unable to install Enterprise Library on Windows 7 64-bit Computer

New Post: Could not load type error related to ReliableSqlConnection

$
0
0
The exception mentions trying to find EnterpriseLibraryContainer, which existed in version 5 but was removed in version 6. The list of packages has version 5 listed as well.

I would remove the version 5 packages and ensure that the configuration files are referencing the version 6 assemblies.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Member Name Matching Rule

$
0
0
Thanks Fernando,
you saved my day
Yes i could get the rule working.
didnt realize it was a AND condition applied among the rules
I thought it was a OR condition applied among the rules

New Post: Specify multiple config file in enterpriseLibrary.ConfigurationSource

$
0
0
Thanks Randy, This worked for us with small change.

New Post: Could not load type error related to ReliableSqlConnection

$
0
0
Hi Randy

Thank you for your reply. I have removed the version 5 package that I was using however this presents a different problem. My project I think has the right references but when I try using these references they are unrecognised so my program won't even build. This was why I added the version 5 package in the first place. Do you know what might cause this?

Thanks

Alex

New Post: Could not load type error related to ReliableSqlConnection

New Post: Could not load type error related to ReliableSqlConnection

$
0
0
Hi Randy

Thanks again - It is .NET 4.5 however this is a project that I had previously written for an earlier version of .NET is it possible this is the problem?

Thanks

Alex

New Post: Can I change the connection string if I use EnterpriseLibraryContainer.Current.GetInstance(..)

$
0
0
Hi

I am connecting to a database using
EnterpriseLibraryContainer.Current.GetInstance<Database>(ID)
I would like to change the connection string before the EL uses it.

Is this possible?

If I try
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>(ID);
db.ConnectionString = myAlteredConnectionString;
then it fails as the ConnectionString is readonly.

I am using EL 5. I create the database this way because it uses either Oracle.ManagedDataAccess.Client or System.Data.OracleClient (depends on the environment).

Thanks for any help,
Jason

New Post: Can I change the connection string if I use EnterpriseLibraryContainer.Current.GetInstance(..)

$
0
0
The approach in the posting FLuent API configuration AND file based configuration will work for you.

The key is to get Enterprise Library to also load the file based configuration. The posted approach will allow you to specify the database configuration programmatically in code and the logging and exception handling configuration in XML.

Just make sure that the XML configuration references the same database key that you will configure programmatically.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to

New Post: Could not load type error related to ReliableSqlConnection

$
0
0
To me it still sounds like a version issue -- perhaps double check all of the assemblies to ensure they got upgraded. if you don't find anything, a sample solution might shed some light on the issue.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Viewing all 1928 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>