DAAB: Unable to convert OracleRefCursor to OracleDataReader using ODPNet

Topics: Data Access Application Block, Enterprise Library Core
Mar 4, 2010 at 3:29 PM

I am trying to call an oracle stored procedure and am using the EL DAAB, the procedure takes in a couple of varchar2 values and returns one refcursor.


 I am using the Enterprise Library DAAB for ODPNet -EntLibContrib.Data.OdpNet.dll assembly version


Public Class DBAccess

Dim ds As New DataSet()

Dim dr As System.Data.IDataReader

Private dBConnection As String = NCCIConfig.GetConnectString("MDC")

Private db As New EntLibContrib.Data.OdpNet.OracleDatabase(dBConnection)

Private transaction As Common.DbTransaction Dim parameters(0) As Object

Private connection As OracleConnection

Public Function execSprocDRCursor(ByVal sprocName As String, ByVal cmdparameters As Object) As System.Data.IDataReader

Dim cw As System.Data.Common.DbCommand

Dim parameters(UBound(CType(cmdparameters, Array))) As Object

Dim dr2 As Oracle.DataAccess.Client.OracleDataReader

parameters = CType(CType(cmdparameters, Array).Clone, Object())

cw = db.GetStoredProcCommand(sprocName, parameters)

dr2 = CType(db.ExecuteReader(cw), OracleDataReader)

execSprocDRCursor = dr2

End Function

Error/Stack Trace:

I have been getting this error Error: System.InvalidCastException Unable to cast object of type 'Oracle.DataAccess.Client.OracleDataReader' to type 'Oracle.DataAccess.Types.OracleRefCursor'. at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) at Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteReader(DbCommand command, CommandBehavior cmdBehavior) at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteReader(DbCommand command) at EntLibContrib.Data.OdpNet.OracleDatabase.ExecuteReader(DbCommand command) at Data.DBAccess.execSprocDRCursor(String sprocName, Object cmdparameters) in C:\Data Services\External\DFR\Data\Common\DBAccess.vb:line 55 at NCCI.DFR.UnitCustomReportRequest.GetQualityTrackingByGrp(String groupID, String rptYr, String rptQrtr, String sbmsnTypeCd) in C:\Data Services\External\DFR\DFR\CustomReport\UnitCustomReportRequest.aspx.vb:line 521 at NCCI.DFR.UnitCustomReportRequest.Page_Load(Object sender, EventArgs e) in C:\Data Services\External\DFR\DFR\CustomReport\UnitCustomReportRequest.aspx.vb:line 11 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Mar 5, 2010 at 7:09 AM


On which line do you get this exception?

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.

Mar 8, 2010 at 5:10 AM

There is a work item in the contrib for this issue - http://entlibcontrib.codeplex.com/WorkItem/View.aspx?WorkItemId=15887.  The issue was fixed, do you have different versions of the Oracle assembly on your machine?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Apr 20, 2010 at 4:51 PM


Dim dr2 As Oracle.DataAccess.Client.OracleDataReader


to the common idatareader along with the corresponding line dr2 = CType(db.ExecuteReader(cw), OracleDataReader)

It works now.  Thanks Jon