Creating a db class .. was wondering why this code fails when I try to .executereader
mSQLDBConnector is an sql object, I debugged it and it goes through and connects to an sql connection object and it even opens the connection.Code:Public Function UseSQLDBExecuteReader() As SqlDataReader Dim lRead As SqlDataReader If mSQLDBCmd Is Nothing Then Throw New Exception("Must use SetSQLDBCommand to initialize SQLCommand object!") Exit Function End If If mSQLDBConnector Is Nothing Then mSQLDBConnector = New SqlConnection(mSQLDBConnString) mSQLDBConnector.Open() else If Not IsSQLDBOpen() then mSQLDBConnector.Open() end if End If Try With mSQLDBCmd .Connection = mSQLDBConnector lRead = .ExecuteReader() End With Return lRead Catch ex As Exception MsgBox("An error occurred:" & Environment.NewLine() _ & ex.ToString() & Environment.NewLine() _ & ex.StackTrace()) Finally lRead.Close() lRead = Nothing mSQLDBConnector.Close() mSQLDBConnector = Nothing End Try End Function
Then It goes to the with statement sets the connection for that, and right when it hits the execute reader it fails stating that the reader needs an available and open connection, which I thought it had both considering I debugged it?
The heck ?




Reply With Quote