User bio
404 bio not found
Member since Nov 6, 2015
Replies:

Hi Antonio,

Are you using the IRISClient assembly from your IRIS 2024.1.0? 

I have Visual Studio 2022, I am using InterSystems.Data.IRISClient.dll from my C:\InterSystems\IRIS20241\dev\dotnet\bin\net7.0.

I have an image file 

03/28/2024  09:28 AM         5,261,669 myimage.png

I use following sample .Net app that I borrow from Cache 2018 and modify all Cache references with IRIS references, I have no problem inserting the 5.2MB image file into a blob field in my test table.

Harry

using System;
using System.IO;

// Add the following using statement
using InterSystems.Data.IRISClient;

namespace C_SharpConsoleExample
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class ConsoleApp
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //

            // Create a connection to Cache
            IRISConnection conn = new IRISConnection();

            // Cache server Connection Information
            // Set Server to your IP address and port to Cache SuperServer port, Log File is optional
            conn.ConnectionString = "Server = localhost; Log File=cprovider.log;Port=1972; Namespace=USER; Password = SYS; User ID = _SYSTEM;";

            //Open a Connection to Cache
            conn.Open();

            // Create table with streams
            IRISCommand dropCmd = new IRISCommand("drop table Sample.Streams", conn);
            try
            {
                dropCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //Do nothing
                string test = ex.Message;
            }

            // Create table with streams
            IRISCommand cmd = new IRISCommand("create table Sample.Streams(binaryData LONGVARBINARY, characterData LONGVARCHAR)", conn);
            cmd.ExecuteNonQuery();

            // Insert stream data into table
            cmd.CommandText = "insert into Sample.Streams(binaryData, characterData) values (?, ?)";

            // One way to mark the parameter as a binary stream datatype and then set the Value
            cmd.Parameters.Add(new IRISParameter("binaryData", IRISDbType.LongVarBinary));
            cmd.Parameters[0].Value = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // An alternate way to bind the data to the parameter and then mark the parameter as a character stream
            cmd.Parameters.Add(new IRISParameter("characterData", (string)"This is a short character stream!"));
            cmd.Parameters[1].IRISDbType = IRISDbType.LongVarChar;

            cmd.ExecuteNonQuery();

            // Now insert two files from disk as streams
            // Open binary file and read into byte[]
            // FileStream fbs = new System.IO.FileStream(".\\ConsoleStream.exe", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            FileStream fbs = new System.IO.FileStream(".\\myimage.png", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
            int filebLen = (int)fbs.Length;
            byte[] filebData = new byte[filebLen];
            fbs.Read(filebData, 0, (int)filebLen);
            fbs.Close();
            cmd.Parameters[0].Value = filebData;
            cmd.Parameters[0].Size = filebLen;

            // Open character file and read into string
            StreamReader fcs = new StreamReader(new System.IO.FileStream(".\\cprovider.log", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite));
            string filecData = fcs.ReadToEnd();
            int filecLen = filecData.Length;
            fcs.Close();
            cmd.Parameters[1].Value = filecData;
            cmd.Parameters[1].Size = filecLen;

            cmd.ExecuteNonQuery();

            cmd.Parameters.Clear();

            // Create an SQL Statement to execute (Command)
            cmd.CommandText = "select ID,* from Sample.Streams";

            // Execute and fetch the data from Cache
            IRISDataReader reader = cmd.ExecuteReader();
            Console.WriteLine("Output from statement: " + cmd.CommandText);
            Console.WriteLine(" ");
            Console.WriteLine("ID\tbinaryStream\t\tcharacterStream ");
            while (reader.Read())
            {
#if BYNUMBER
                // Access Column by Number
                Console.Write(reader[0]);
                Console.Write("\t");
                Console.Write(reader[1] + " : N/A");
                Console.Write("\t");
                Console.Write(reader[2]);
                Console.Write("\t");
                Console.WriteLine();
#else
                // Access Column by Name
                Console.Write(reader[reader.GetOrdinal("ID")]);
                Console.Write("\t");
                Console.Write(reader[reader.GetOrdinal("binaryData")] + " : N/A");
                Console.Write("\t");
                Console.Write(reader[reader.GetOrdinal("characterData")]);
                Console.Write("\t");
                Console.WriteLine();
#endif
            }
            Console.WriteLine("");
            Console.WriteLine("End of characterStream output!");

            // Cleanup Reader, Connection and Command
            reader.Close();
            cmd.Dispose();
            conn.Close();
        }
    }
}

Hi Jim.

You are using parameterized sql query statement against your Oracle linked table, in ObjectScript context, string delimiter is double quote, can you try just put one single quote in your PrepStmtData variable and bind it to the prepared statement against your Oracle table?

PrepStmtData="Monika's Test AC"

Certifications & Credly badges:
Harry has no Certifications & Credly badges yet.
Global Masters badges:
Harry has no Global Masters badges yet.
Followers:
Harry has no followers yet.
Following:
Harry has not followed anybody yet.