Hi,
I am planning to use LLBLGen with SQL CE 3.5 database on the desktop application.
By default, DataAccessAdapter creates a new database connection, and disposed it internally. However, releasing a SQL CE database connection is an expensive operation - because there is no connection pool for SQL CE database, and also it releases database file.
http://blogs.msdn.com/b/sqlservercompact/archive/2009/05/05/sql-server-compact-garbage-collection-whys-and-hows.aspx
To avoid a connection open/close for every DataAccessAdapter instance due to performance reason, I've made a new class that inherits from DataAccessAdapter, and overridden CreateNewPhysicalConnection as follow:
public class DataAccessAdapterExtended : DataAccessAdapter
{
private System.Data.Common.DbConnection _connection;
public MyDataAccessAdapter(DbConnection connection) : base(true)
{
// Provide an active database connection in CTor
this._connection = connection;
}
protected override System.Data.Common.DbConnection CreateNewPhysicalConnection(string connectionString)
{
// Returns the same active database connection
return this._connection;
}
}
However, I can not dispose "DataAccessAdapterExtended" instance, because it disposes the physical connection instance internally. It means, there are some internal instances of DataAccessAdapter, which is not disposed correctly - and may cause a memory leak!
Would it be possible to have an another virtual method in DataAccessAdapterBase, which is responsible for disposing a database connection?
Class: DataAccessAdapterBase
protected virtual void DisposePhysicalConnection(System.Data.Common.DbConnection connection)
{
// ... DataAccessAdapterBase should dispose the physical connection in this method
// ... so developer can override this behaviour easily.
}
Currently, Adapter allows me to handle creation of the physical connection, but it does not allow me to manage dispose/closing - which causes me a trouble.
Would you please suggest me an alternative or any better way to handle this situation?
Kind Regards,