I have a SqlDB.dll that has the function:
public SqlDataReader getEnumValues(int enumId)
{
SqlDataReader reader = null;
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command =
new SqlCommand(
"SELECT * FROM [EnumValue] WHERE enumId LIKE '" + enumId + "';",
connection);
reader = command.ExecuteReader();
//if(reader.Read())
// Debug.WriteLine("Inside sqlDb->getEnumValues command = " + command.CommandText + " reader[name] = " + reader["name"].ToString() + " reader[value] = " + reader["value"].ToString() + " reader[description] = " + reader["description"].ToString());
}
//reader.Close();
return reader;
}
As you can see I have tried closing the reader before returning it, and also I read the data inside and it's ok. I'm using the function like this:
using (SqlDataReader getEnumValuesReader = (SqlDataReader)getEnumValues.Invoke(sqlDB, getEnumValuesForEnumParam))
{
Debug.WriteLine("Success getEnumValues -- ");
if (getEnumValuesReader.HasRows)
{
while (getEnumValuesReader.Read()) //Loop throw all enumValues and add them to current enum
{
try
{
values.Add(new Model.EnumValue(getEnumValuesReader["name"].ToString(), getEnumValuesReader["value"].ToString(), getEnumValuesReader["description"].ToString()));
Debug.WriteLine("Value[0].name = " + values[0].Name);
}
catch (Exception ex)
{
Debug.WriteLine("Error in building new EnumValue: " + ex.Message);
}
}
}
}
and I'm getting exception of type 'System.InvalidOperationException'
I'm guessing it has something to do with the Sqldatareader being passed.