[Mono-bugs] [Bug 424897] New: Assignment to OracleLob throws exception

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Sep 9 14:58:38 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=424897


           Summary: Assignment to OracleLob throws exception
           Product: Mono: Class Libraries
           Version: 2.0
          Platform: x86-64
        OS/Version: SLES 10
            Status: NEW
          Severity: Blocker
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: bnc-blr-team-mono at forge.provo.novell.com
        ReportedBy: webservices at landmarkdigital.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development


In the example below, when the assignment is made to p1.Value, an exception is
thrown.  This code works in .NET 2.0.  There appears to be no way to create a
blob oracle input paramter for a stored procedure call.

using System;
using System.Data;
using System.Data.OracleClient;

namespace BlobTest
{
        class MainClass
        {
                public static void Main(string[] args)
                {
                        checkTNS();
                        InsertBlob();
                }

                public static void checkTNS()
            {
              string tnsAdmin =
System.Environment.GetEnvironmentVariable("TNS_ADMIN");
              if ( (tnsAdmin == null)
                || (string.Empty.Equals(tnsAdmin)) )
              {
                System.Environment.SetEnvironmentVariable("TNS_ADMIN",
"/home/tns");
              }
            }


                public static decimal InsertBlob()
        {
            byte[] ByteArray = new byte[2000];
            decimal retVal = -1;

            string sproc = "MyPackage" + ".InsertBlob";

            OracleCommand cmd = new OracleCommand();

            cmd.CommandText = sproc;

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Connection = new OracleConnection(@"Data Source=mysource;User
Id=myuser;Password=mypass");

            cmd.Connection.Open();

            cmd.Transaction = cmd.Connection.BeginTransaction();

            try
            {



                OracleParameter p1 = new OracleParameter("i_Sig_File",
OracleType.Blob);


                p1.Direction = ParameterDirection.Input;

                //EXCEPTION thrown here
                p1.Value = GetOracleLob(cmd.Transaction, ByteArray);

                cmd.Parameters.Add(p1);



                cmd.ExecuteNonQuery();

                cmd.Transaction.Commit();

            }

            catch(Exception ex)
            {
                Console.WriteLine("I exploded:" + ex.ToString());
                cmd.Transaction.Rollback();

            }

            return retVal;

        }



        private static OracleLob GetOracleLob(OracleTransaction transaction,
byte[] blob)
        {

            string BLOB_CREATE = "DECLARE dpBlob BLOB; BEGIN "

            + "DBMS_LOB.CREATETEMPORARY(dpBlob , False, 0); :tempBlob :=
dpBlob; "

            + "END;";

            OracleLob tempLob = OracleLob.Null;

            if (blob != null)
            {

                // Create a new command using the same connection

                OracleCommand command = transaction.Connection.CreateCommand();

                // Assign the transaction to the command

                command.Transaction = transaction;

                // Create blob storage on the Oracle server

                command.CommandText = BLOB_CREATE;

                // Add a new output paramter to accept the blob storage
reference

                command.Parameters.Add(

                new OracleParameter("tempBlob", OracleType.Blob)).Direction =

                ParameterDirection.Output;

                // Fire as your guns bear...

                command.ExecuteNonQuery();

                // Retrieve the blob stream from the OracleLob parameter 

                tempLob = (OracleLob)command.Parameters[0].Value;

                // Prevent server side events from firing while we write to the
stream

                tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);

                // Write bytes to the stream

                tempLob.Write(blob, 0, blob.Length);

                // Resume firing server events

                tempLob.EndBatch();

            }

            return tempLob;

        }
        }
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list