locked
ExecuteReader exception RRS feed

  • Question

  • User-1916667149 posted

    Hi All,

    I am trying to read CLOB field from oracle database table by using ExecuteReader method. However, when I try to do so, it gives me an exception as "Data type is not supported". The field ACTIVITY_COMMENT is a CLOB field and it contains RTF data in it. 

    It gives an exception at the line  - myOleDbDataReader = myOleDbCommand.ExecuteReader();

    My code is as follows -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.OleDb;
    //using System.Windows.Forms.dll;
    
    namespace ConsoleApplication1
    {
        class ConvertFromRTF
        {
    
            static void Main()
            {
                /* connecting to oracle 
                 * */
    
                string connectionString = "provider=MSDAORA;data source=Oracle12;user id=crmprod;password=crmprod";
                OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
    
                OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();    
    
                myOleDbCommand.CommandText = "SELECT ACTIVITY_COMMENT, DATE_ADDED, STAMP2 FROM ACTIVITY WHERE STAMP2 = 'C83AC8C1F6030001'";
    
                myOleDbConnection.Open();
                OleDbDataReader myOleDbDataReader = null;
                try
                {
                    myOleDbDataReader = myOleDbCommand.ExecuteReader();             }
                catch(Exception e)
                {
                    Console.WriteLine(e);
                }
    
    
                myOleDbDataReader.Read();
    
                Console.WriteLine("myOleDbDataReader[\" ACTIVITY_COMMENT\"] = " + myOleDbDataReader["ACTIVITY_COMMENT"]);
                Console.WriteLine("myOleDbDataReader[\" DATE_ADDED\"] = " + myOleDbDataReader["DATE_ADDED"]);
                Console.WriteLine("myOleDbDataReader[\" STAMP2\"] = " + myOleDbDataReader["STAMP2"]);
    
    
    
                string plaintext = "";
    
                try
                {
                    plaintext = (string)myOleDbDataReader["ACTIVITY_COMMENT"];
                }
                catch
                {
                    Console.WriteLine("Exception caught");
                }
    
                myOleDbDataReader.Close();
                myOleDbConnection.Close();
    
                string path = @"test.rtf";
    
                //Create the RichTextBox. (Requires a reference to System.Windows.Forms.dll.)
                System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
    
                // Get the contents of the RTF file. Note that when it is
                // stored in the string, it is encoded as UTF-16.
                string s = System.IO.File.ReadAllText(path);
    
                // Display the RTF text.
                System.Windows.Forms.MessageBox.Show(s);
    
                // Convert the RTF to plain text.
                rtBox.Rtf = s;
                plaintext = String.Concat(plaintext,rtBox.Text);
    
                // Display plain text output in MessageBox because console
                // cannot display Greek letters.
                System.Windows.Forms.MessageBox.Show(plaintext);
    
                // Output plain text to file, encoded as UTF-8.
                System.IO.File.WriteAllText(@"output.txt", plaintext);
            }
        }
    
    
    }
    
     
    Can anyone help me out on this. Thanks in advance....
    Saturday, October 8, 2011 5:52 PM

Answers

  • User269602965 posted

    Use ODP.NET/Oracle DataAccess Client instead of OLEDB.  There are fewer restrictions than found with OLEDB and it is faster.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 9, 2011 3:21 PM