I keep getting 'Invalid attempt to read when data is present' at line retObj.DatabaseID = DR.GetString(0)
I checked the connection str: works fine
I checked the SQL str: work fine

VB Code:
  1. Public Class NetDatabase    ...'properties hidden            
  2. Public Function GetDetails(ByVal DatabaseID As String) As NetDatabase              
  3. Dim retObj As New NetDatabase              
  4. Dim DR As SqlDataReader              
  5. Dim dataAcc As New DataAccess            
  6.  Try                  
  7. DR = dataAcc.GetData("SELECT * FROM [database] where DatabaseID ='" & DatabaseID & "'")                  
  8.  retObj.DatabaseID = DR.GetString(0)                
  9.  retObj.DatabaseName = DR.GetString(1)                
  10.  retObj.Domestic = DR.GetString(2)                
  11.  retObj.Connectionstring = DR.GetString(3)                  
  12.  Return retObj              
  13. Catch ex As Exception                
  14.  MsgBox(ex.ToString)            
  15.  End Try        
  16.  End Function        
  17. End Class        
  18.  
  19. Private Class DataAccess                    
  20. Dim mConnectionString As String = "SERVER=192.168.0.1;DATABASE=DEV_NETUSERDB;UID=sa;PWD=pwd;"          
  21. Private ReadOnly Property ConnectionString() As String              
  22. Get                  
  23. Return mConnectionString              
  24. End Get          
  25. End Property    
  26.        
  27. Public Function GetData(ByVal SQLstr As String) As SqlDataReader              
  28. Dim sqlDR As SqlDataReader              
  29. Dim DA As New DataAccess              
  30. Try                    
  31. Dim sqlCn As New SqlConnection(DA.mConnectionString)                  
  32. Dim sqlCmd As New SqlCommand(SQLstr, sqlCn)
  33.   sqlCn.Open() 'open connection with sql string                    
  34. If UCase(Left(SQLstr, 6) = "SELECT") Then                    
  35.  sqlDR = sqlCmd.ExecuteReader                    
  36.  While sqlDR.Read()                          
  37. sqlDR.Close()  'Why? Cos MSDN Says:you cannot retrieve output parameters until after you call Close.
  38. Return sqlDR                    
  39. End While                  
  40. Else                      
  41. sqlCmd.ExecuteNonQuery()                    
  42. End If                    
  43. sqlCmd.Connection.Close()                                
  44. Catch ex As Exception                
  45. MsgBox(ex.ToString)              
  46. End Try        
  47. End Function      
  48. End Class


Has someone out there have any idea why?