none
Insert Blob <= 8000 Bytes RRS feed

  • Question

  • Using ADO.NET 2.0 I’m trying to insert some data into a byte (blob) column in an Informix IDS v10.0 database. The insert fails with the following error:

    Illegal attempt to convert Text/Byte blob type.

    The code is as follows:

            private void InsertBlob()

            {

                DbProviderFactory provider = DbProviderFactories.GetFactory("System.Data.Odbc");

                using (DbConnection connection = provider.CreateConnection())

                {

                    connection.ConnectionString = "DSN=mydb";

                    connection.Open();

                    using (DbCommand command = connection.CreateCommand())

                    {

                        command.CommandText = "insert into blobtable(blobdata) values(?)";

                        DbParameter parameter = command.CreateParameter();

                        parameter.DbType = DbType.Binary;

                        parameter.Value = new byte[8000];  // ç change to 8001 and the insert succeeds

                        command.Parameters.Add(parameter);

                        command.ExecuteNonQuery();

                    }

                }

            }

     

    If, however, I change the dimension of the byte array to 8001, the insert succeeds. I’d like to understand why this is the case, and how can I insert blob data of 8000 bytes or less? It is not clear to me whether this is a .NET or Informix issue, but given the discussion over the apparently poorly-worded description for System.Data.DbType.Binary I thought I should try here first.

    In case it matters I’m using v2.90.00.12949 of the IBM Informix ODBC driver.

     

    Thank you,

    Mike

     

    Saturday, September 22, 2007 6:18 PM

Answers

  • For what it's worth, this issue is resolved with at least .NET 3.5 SP1 and Informix CSDK 3.50. I can now successfully insert data of 8000 characters or less using DbType.Binary.

    Mike
    Tuesday, September 1, 2009 3:34 PM