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.
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.