4.1, postgresql, adapter wrapper dispose

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 14-Mar-2014 11:25:42   

Hi,

a few years ago I've created an adapter wrapper, which is usually used to pass an adapter between application modules (if neccessary). It works correctly, but today, I've found a problem with disposing this object. Probably it is connected with npgsql driver upgrade which we've made a few weeks ago. The biggest problem is that exception occures randomly.

I'm wondering whether my adapter wrapper dispose method is correct according to llblgen guidlines.

private bool isDisposed = false;

        ~ApCDBTransaction()
        {
            Dispose();
        }

        public void Dispose()
        {
            lock (this)
            {
                if (this.isDisposed == false)
                {
                    this.isDisposed = true;

                    Rollback();

                    this.adapter.CloseConnection();

                    this.adapter.Dispose();
                }
            }
        }

I'm wondering, whether the close connection is necessary. Does the Dispose method on the llglben adapter object always invoke the CloseConnection method on the database driver or does it depend on some other mehinisms, configuration, etc. ? Can I safely remove the this.adapter.CloseConnection(); line?

Unhandled exception has happend: Cannot access a disposed object. Object name: 'NpgsqlConnection'.;Cannot access a disposed object. Object name: 'NpgsqlConnection'.StackTrace: at Npgsql.NpgsqlConnection.CheckNotDisposed() in c:\C#Apps\github.npgsql.Npgsql.stock\src\Npgsql\NpgsqlConnection.cs:line 926 at Npgsql.NpgsqlConnection.get_FullState() in c:\C#Apps\github.npgsql.Npgsql.stock\src\Npgsql\NpgsqlConnection.cs:line 386 at Npgsql.NpgsqlConnection.get_State() in c:\C#Apps\github.npgsql.Npgsql.stock\src\Npgsql\NpgsqlConnection.cs:line 406 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CloseConnection() in c:\Myprojects\VS.NET Projects\LLBLGen Pro v4.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 927 at Implementation.LLBLGen.Dependent.Adapters.ApCDBTransaction.Dispose()

Best Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Mar-2014 15:26:45   

The Adapter closes the connection when being disposed, but nevertheless, you can try and catch on the closeConnection as well as the Rollback as well.