EntLib Data Access block with Oracle Odp OUT parameters

April 18th, 2008

My code has been failing when getting values out of procedures when I switch from the Microsoft provider to the Odp provider inside the Data Access App Block.
Here is some typical code:

Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCmd = db.GetStoredProcCommand("AUTH_LOGIN");
db.DiscoverParameters(dbCmd);
DbParameterCollection cmdParams = dbCmd.Parameters;
cmdParams["P_OSNAME"].Value = criteria.Username;
cmdParams["P_INCOMING_PASSWORD"].Value = criteria.Password;
db.ExecuteNonQuery(dbCmd);
authenticationReturnCode =
Convert.ToInt32(db.GetParameterValue(dbCmd, "P_RET_CODE"));

This doesn’t work - it fails with an exception:
Unable to cast object of type ‘Oracle.DataAccess.Types.OracleDecimal’ to type ‘System.IConvertible’.

P_RET_CODE is defined as a NUMBER OUT in the procedure.

It seems that the DiscoverParameters call doesn’t set up the OUT parameter quite right, even though it looks fine. However, if you explicitly tell it the expected data type it decides to work (this line comes just before the ExecuteNonQuery):

cmdParams["P_RET_CODE"].DbType = System.Data.DbType.Decimal;

Posted in Development |

Comments

Leave a Reply

You must be logged in to post a comment.