Error inserting CLOB.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for universal data access
Post Reply
daleybox
Posts: 1
Joined: Wed 06 Feb 2008 20:19

Error inserting CLOB.

Post by daleybox » Wed 06 Feb 2008 20:25

I'm trying to insert a CLOB into Oracle 11g. I am using the following C# code:

parameter = cmd.Parameters.Add("SOURCETEXT", UniDbType.Clob);
parameter.Value = sSourceText;
cmd.Parameters.Add(parameter);

The parameter value is correct when I look at the debugger, however, I always get an error when I try to execute the query with:

cmd.ExecuteNonQuery();

I get the error "Can not convert." The UniDbType field in the cmd.Parameters for this has the following error in it.

UniDbType '((CoreLab.UniDirect.UniParameter)((new System.Collections.ArrayList.ArrayListDebugView(((CoreLab.Common.DbParameterBaseCollection)(cmd.Parameters.System.Collections.ICollection.SyncRoot)).InnerList)).Items[9])).UniDbType' threw an exception of type 'System.ArgumentException' CoreLab.UniDirect.UniDbType {System.ArgumentException}

Can someone tell me what I am doing wrong. I have fix or six other fields with the same structure (just different UniDbTypes) and they work fine.

Thanks.

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Thu 07 Feb 2008 09:10

Please send me a small test project to reproduce the problem.
It is desirable to use 'test' schema objects, otherwise include the
definition of your own database objects.
Do not use third party components.

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Thu 07 Feb 2008 10:41

We reproduced the error. This bug will be fixed in the nearest future.
Meanwhile, as a temporary solution, you can use the UniBlob class for CLOB inserting.
See the example:

Code: Select all

using (UniConnection uniConnection = new UniConnection(myConnectionString)) {

        uniConnection.Open();

        UniCommand command = uniConnection.CreateCommand();
        command.CommandText = "INSERT INTO uni_clob (ID, SOURCETEXT) VALUES (:ID, :SOURCETEXT)";

        UniBlob uniBlob = CreateClob(uniConnection, "my string");

        UniParameter param = new UniParameter("ID", UniDbType.Int);
        param.Value = 1; // just test value, usually obtained from sequence
        command.Parameters.Add(param);
        param = new UniParameter("SOURCETEXT", UniDbType.Clob);
        param.Value = uniBlob;
        command.Parameters.Add(param);

        command.ExecuteNonQuery();
      }


private UniBlob CreateClob(string value) {

      UniBlob uniBlob = new UniBlob(uniConnection, UniDbType.Clob);
      byte[] chars = Encoding.Default.GetBytes(value);
      uniBlob.Write(chars, 0, chars.Length);
      return uniBlob;
    }

---------------------------------------
Used table

CREATE TABLE UNI_CLOB (
  ID NUMBER,
  SOURCETEXT CLOB)

Post Reply