Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read oracle blob data through ODBC connection ADO.net

447114Jul 9 2005
Hi,

How to read blob data in Oracle database using ODBC connection in ADO.NET(c#). I'm using Oracle 10g .

I have tried the following code but i couldn't succeed. If you know where i'm doing mistake means guide me.
Whether my SelectQuery is correct.


using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
using System.IO;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace Blob
{
class Program
{
static void Main(string[] args)
{
try
string constr = "DSN=Test;Server=ORCL;UId=scott;Pwd=tiger;Driver={Microsoft ODBC for Oracle};";

OdbcConnection oCon = new OdbcConnection(constr);
oCon.Open();
string SelectQuery = "SELECT content from PS_TXN WHERE id = 75; ";

OdbcCommand oCmd = new OdbcCommand();
oCmd.Connection = oCon;
oCmd.CommandText = SelectQuery;
oCmd.CommandType = System.Data.CommandType.Text;
OdbcParameter odbcReadParam = new OdbcParameter("blobfromdb",OdbcType.Image ) ;
odbcReadParam.Direction = System.Data.ParameterDirection.Output;
oCmd.Parameters.Add(odbcReadParam);
odbcReadParam.SourceColumn = "Content";

byte[] byteData = new byte[0];
object obj = oCmd.Parameters[0].Value; //this value always shows null
if (obj != null)
{
Console.ReadLine();
int ArraySize = new int();
ArraySize = byteData.GetUpperBound(0);
FileStream fs1 = new FileStream(@"e:\Vinoth\airport-tunnel-blur.jpg",
FileMode.OpenOrCreate, FileAccess.Write); fs1.Write(byteData, 0, ArraySize);
fs1.Close();
Console.ReadLine();
}
}
catch (OracleException e){
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}


Please help me to find solution.

Regards,
Vinoth
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2005
Added on Jul 9 2005
0 comments
2,984 views