vijay
vijay

Reputation: 655

Storing binary file to Oracle Blob field in C#

We have our own DataAccess library built upon the Microsoft Enterprise Data Access block.

I have stored procedure that takes binary file content as input parameter and store it into DB.

byte[] imageFileByteArray = this.GetByteArrayFromFile(imageFile);
this.dataAccess.AddCmdParameter("DOCIMAGE", System.Data.DbType.Binary, imageFileByteArray);

This code is working fine when using SQL database, But when I switched to Oracle, I get the exception saying that "Wrong type of parameter"

In oracle db, the DOCIMAGE column is declared as BLOB field.

Why inferred Dbtype.Binary is not working for oracle?

Upvotes: 0

Views: 3405

Answers (2)

Adrian Ciura
Adrian Ciura

Reputation: 1112

This is probably to do with different Oracle inference of OracleDbType from System.Data.DbType. The System.Data.DbType.Binary has coresponding OracleDbType=Raw. You would have to use System.Data.DbType.Object to get OracleDbType=Blob, for more details see Table 3-3 in http://docs.oracle.com/html/B14164_01/featOraCommand.htm

Upvotes: 0

Justin Harvey
Justin Harvey

Reputation: 14672

You will need to use an OracleParameter, with the OracleType enum value Blob, see here for more...

http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracletype.aspx

Upvotes: 1

Related Questions