title: How to fix “Invalid operation on a closed object” exception when trying to Read an OracleDataReader
body: <p>I'm creating a web API using .Net Core and the Oracle.ManagedDataAccess.Core plugin that accesses an Oracle database to retrieve a Blob field and return it as a byte array. I created a function (getBlobfromDB) that gets the Oracle connection string from an encrypted field on a SQL database, connects and uses an OraleDataReader to retrieve and return the Blob field. But when the OraleDataReader tries to Read the record, I'm getting this exception: "Invalid operation on a closed object".</p>
  
  <p>When you search for this issue, the most relevant answer is this <a href="https://stackoverflow.com/questions/33526111/oracle-invalidoperationexception-when-trying-to-select-from-a-table">post</a></p>
  
  <p>However, I'm 100% percent sure that user on the conn string has access since that is the schema owner, and I also tried adding the schema owner to the Select query (SELECT FIELD FROM SCHEMA_OWNER.TABLE WHERE ID = "") getting the same error</p>
  
  <p>So I tried two other things, getting a different VARCHAR field from another table on the same database, still getting the same error; and trying on a different Oracle database and I was able to successfully retrieve the data. I noticed that the Oracle versions on the servers are different, 12.2 for the working one and 11.2 for the non-working, this may be the reason?  I don't know what else I can do or try, I'll appreciate any help/advice that you can give me</p>
  
  <p>This is the simplified function</p>
  
  <pre><code>private OracleBlob getBlobfromDB(string sSystem, string sID)
          {
              string sSQL = String.Empty;
              string connString = String.Empty;
              OracleConnection oConn = new OracleConnection();
  
              if (string.IsNullOrWhiteSpace(sID) || string.IsNullOrWhiteSpace(sSystem) )
              {
                  return null;
              }          
  
              sSQL = "SELECT BLOB_FIELD FROM TABLE WHERE ID = " + sID;
              connString = getConnectionString(sSystem); 
  
              try
              {
                  using (oConn = new OracleConnection(connString))
                  { 
                      oConn.Open();
                      OracleCommand oCom = new OracleCommand(sSQL, oConn);                   
  
                      OracleDataReader oDr = oCom.ExecuteReader();                    
                      if (oDr.HasRows)
                      {      
                          //I'm able to reach to this point before getting the exception
                          oDr.Read();
                          OracleBlob blob = oDr.GetOracleBlob(0);                        
                          // Clean up
                          oDr.Close();
                          oDr.Dispose();
                          oCom.Dispose();
                          return blob;
                      }
                      else
                      {
                          // Clean up
                          oDr.Close();
                          oDr.Dispose();
                          oCom.Dispose();
                          return null;
                      }
  
                  }
              }
              catch (Exception x)
              {
                  return null;
              }
              finally
              {
                  oConn.Close();
              }
          }
  </code></pre>