R
Robert Scheer
Hi.
I am using VS.NET 2003. I have a function that runs a procedure and
returns a SqlDataReader:
Public Overloads Function RunProcedure(ByVal StoredProcName As String,
_
ByVal Parameters As IDataParameter()) As SqlDataReader
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim returnReader As SqlDataReader
Try
cn = New SqlConnection
cn.ConnectionString = strConnectionString
cn.Open()
cmd = BuildQueryCommand(StoredProcName, Parameters)
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
returnReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return returnReader
End Function
When I try to use HasRows on the caller routine, I receive the error:
"Invalid attempt to HasRows when reader is closed".
If I remove the CommandBehaviour.CloseConnection option from the
DataReader this error goes away. Can't I use HasRows and
CommandBehaviour.CloseConnection?
Thanks,
Robert Scheer
I am using VS.NET 2003. I have a function that runs a procedure and
returns a SqlDataReader:
Public Overloads Function RunProcedure(ByVal StoredProcName As String,
_
ByVal Parameters As IDataParameter()) As SqlDataReader
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim returnReader As SqlDataReader
Try
cn = New SqlConnection
cn.ConnectionString = strConnectionString
cn.Open()
cmd = BuildQueryCommand(StoredProcName, Parameters)
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
returnReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return returnReader
End Function
When I try to use HasRows on the caller routine, I receive the error:
"Invalid attempt to HasRows when reader is closed".
If I remove the CommandBehaviour.CloseConnection option from the
DataReader this error goes away. Can't I use HasRows and
CommandBehaviour.CloseConnection?
Thanks,
Robert Scheer