DatabaseConnectionWrapper kills my blob

Topics: Data Access Application Block
Mar 10, 2011 at 12:50 PM

Hello
I´m using the DAAB to get a Logo out of a blob field from an Oracle DB. The SP has 2 Parameters IN LogoNr and out LogoBlob. Every time I try to pick the value via entlib.GetParameterValue(command, "p_LOGO") it´s empty. Here is the small test. I found out that the DatabaseConnectionWrapper Dispose seems to destroys the data. In the file database.cs ExecuteNonQuery I can see the data.

Any ideas?

Thx
Matthias

            try
            {
                Database entlib = DatabaseFactory.CreateDatabase();

                var command = entlib.GetStoredProcCommand("GetLogo");

                entlib.AddInParameter(command, "p_LOGONR", DbType.Int32, 1234);
                entlib.AddOutParameter(command, "p_LOGO", DbType.Object, 100000);

                entlib.ExecuteNonQuery(command);

                var test = entlib.GetParameterValue(command, "p_LOGO") as System.Data.OracleClient.OracleLob;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }



Mar 11, 2011 at 12:35 AM

Have you checked if the value is indeed null without directly casing it to OracleLob?  And could you verify if this happens if the output parameter is of a different data type, say a string.  I know this works as expected for a sql database but I just want to know if this happens specific to OracleLob data type.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 11, 2011 at 8:34 AM

Hello Sarah,
i´ve tested the same procedure with Sql Server it works as expected. The return value string is also working with Oracle.

I found out that when I skip the Dispose in the DatabaseConnectionWrapper everything is working as expected in Oracle.

       protected virtual void Dispose(bool disposing)
        {
            if(disposing)
            {
                int count = Interlocked.Decrement(ref refCount);
                if (count == 0)
                {
                    Connection.Dispose();
                    Connection = null;
                    GC.SuppressFinalize(this);
                }
            }           
        }

 


Mar 14, 2011 at 1:17 AM

I'm not sure what could be the reason for this behavior but what I can suggest is to try creating a connection and a dbtransaction prior to executing your command.  Pass the instance of DbTransaction in the call to ExecuteNonquery.  In this way, you manage the connection and you have control over when it should be closed.  If this works, I suggest you log this in the Issue Tracker.

using(DbConnection connection = database.CreateConnection())
{
       using(DbTransaction transaction = connection.BeginTransaction())
      {
            database.ExecuteNonQuery(command, transaction);
            transaction.Commit();
      }
}

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com