Using OracleType.Raw with C#

  • Thread starter Thread starter john.gillespie
  • Start date Start date
J

john.gillespie

I am trying to insert a byte array into an Oracle DB.

The type of the column in the DB is Raw
The C# type I have is a 16 byte byte[] array.

Whenever I try to do this I get the following error message:

"Type System.Byte[] can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed."

Does anyone know how I should achive this. I have included the code
below:


string sql = @"SELECT PROCESS_ID, PROCESS_NAME,
LAST_MODIFY_RESOURCE, BUSINESS_PROCESS.DESCRIPTION,
VERSION, CHANGE_DATE,
AW_RESOURCE_LAST_MODIFY.NT_NAME FROM BUSINESS_PROCESS LEFT
OUTER JOIN NT_RESOURCE AW_RESOURCE_LAST_MODIFY
ON BUSINESS_PROCESS.LAST_MODIFY_RESOURCE
AW_RESOURCE_LAST_MODIFY.RESOURCE_ID WHERE LAST_MODIFY_RESOURCE =
@UserID ORDER BY CHANGE_DATE DESC";

//Create parameters object to handle method parameters
OracleParameter [] arParms = new OracleParameter[1];
arParms[0] = new OracleParameter("@UserID", OracleType.Raw, 16);
arParms[0].Value = DbHelperOracle.StringToByte(sUserID);

//Retrieve the connection
conn = DbHelperOracle.GetOracleConnection(ConnectionString);
//Execute the statement
dr = DbHelperOracle.ExecuteOracleReader(conn, sql, arParms);
 
My first question is, why would a user id column be of type raw?
Anyway, first I'd use a colon instead of the @ symbol for the parameter
prefix since this is Oracle. That wouldn't cause the above error but I
have the feeling that error is coming from one of the "Helper"
functions.
 
I am trying to insert a byte array into an Oracle DB.

The type of the column in the DB is Raw
The C# type I have is a 16 byte byte[] array.

Whenever I try to do this I get the following error message:

"Type System.Byte[] can not be marshaled as an unmanaged structure; no
meaningful size or offset can be computed."

Does anyone know how I should achive this. I have included the code
below:


string sql = @"SELECT PROCESS_ID, PROCESS_NAME,
LAST_MODIFY_RESOURCE, BUSINESS_PROCESS.DESCRIPTION,
VERSION, CHANGE_DATE,
AW_RESOURCE_LAST_MODIFY.NT_NAME FROM BUSINESS_PROCESS LEFT
OUTER JOIN NT_RESOURCE AW_RESOURCE_LAST_MODIFY
ON BUSINESS_PROCESS.LAST_MODIFY_RESOURCE
AW_RESOURCE_LAST_MODIFY.RESOURCE_ID WHERE LAST_MODIFY_RESOURCE =
@UserID ORDER BY CHANGE_DATE DESC";

//Create parameters object to handle method parameters
OracleParameter [] arParms = new OracleParameter[1];
arParms[0] = new OracleParameter("@UserID", OracleType.Raw, 16);
arParms[0].Value = DbHelperOracle.StringToByte(sUserID);

//Retrieve the connection
conn = DbHelperOracle.GetOracleConnection(ConnectionString);
//Execute the statement
dr = DbHelperOracle.ExecuteOracleReader(conn, sql, arParms);

Please understand that the type 'Raw' is discouraged by Oracle. I
assume you're trying to store a GUID into an Oracle column? It's best
to use char fields for that.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Back
Top