Bug #97242 Return datareader Give Error "Invalid attempt to Read when reader is closed"
Submitted: 16 Oct 2019 3:23 Modified: 22 Oct 2019 11:20
Reporter: Ehab Tharwat Offroad Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.18 OS:Windows
Assigned to: CPU Architecture:Other (I9)

[16 Oct 2019 3:23] Ehab Tharwat Offroad
Description:
When you return a data reader from function it give you the error :
Invalid attempt to Read when reader is closed.

Regarding that the connection is open and its a new created data reader. also its working find in mysql DotNet Connector Ver 6.9.12

How to repeat:
make function return a data reader and read the data from the datareader.

example:
DbProviderFactory dbFactory = DbProviderFactories.GetFactory(AppSetting.ServerSettings.ProviderName);

public static DbDataReader Create(string sSellectString, DbConnection DBConn)
{
                using (DbCommand Cmd =                                    dbFactory.CreateCommand())
                {
                    Cmd.CommandTimeout = 300;
                    Cmd.CommandText = sSellectString;
                    Cmd.Connection = DBConn;
                    return Cmd.ExecuteReader();
                }
            }

public static string FieldValString(string sRequiredField, string sTableName,    string sWhereString, DbConnection DBConn)
            {
                DbDataReader dbReader = DataBuilder.DataReader.Create("Select " + sRequiredField + " From " + sTableName + " Where " + sWhereString + " Limit 1", DBConn);
                string sResult = string.Empty;
                if (dbReader.Read())
                    sResult = dbReader[sRequiredField].ToString();
                dbReader.Dispose();
                return sResult;
}
[19 Oct 2019 6:29] Bradley Grainger
This is a duplicate of bug #89159. It's caused by disposing the MySqlCommand before using the MySqlDataReader.
[22 Oct 2019 11:20] MySQL Verification Team
Thank you, Bradley.
Marking this as duplicate of Bug #89159.

regards,
Umesh