Cast error on SQLDataReader (entlib 5.0, asp.net 3.5, vb)

Posted by Phil on Stack Overflow See other posts from Stack Overflow or by Phil
Published on 2010-05-20T07:20:51Z Indexed on 2010/06/15 19:32 UTC
Read the original article Hit count: 1026

My site is using enterprise library v 5.0. Mainly the DAAB. Some functions such as executescalar, executedataset are working as expected. The problems appear when I start to use Readers

I have this function in my includes class:

Public Function AssignedDepartmentDetail(ByVal Did As Integer) As SqlDataReader
    Dim reader As SqlDataReader
    Dim Command As SqlCommand = db.GetSqlStringCommand("select seomthing from somewhere where something = @did")
    db.AddInParameter(Command, "@did", Data.DbType.Int32, Did)
    reader = db.ExecuteReader(Command)
    reader.Read()
    Return reader
End Function

This is called from my aspx.vb like so:

 reader = includes.AssignedDepartmentDetail(Did)
            If reader.HasRows Then
                TheModule = reader("templatefilename")
                PageID = reader("id")
            Else
                TheModule = "#"
            End If

This gives the following error on db.ExecuteReader line:

Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Data.RefCountingDataReader' to type 'System.Data.SqlClient.SqlDataReader'.

Can anyone shed any light on how I go about getting this working. Will I always run into problems when dealing with readers via entlib?

© Stack Overflow or respective owner

Related posts about enterprise-library

Related posts about sqldatareader