I got this function which belongs to a Windows Form app.
This code works perfectly fine on some machines, but there are specific ones where this function returns a NullReferenceException
. I don't know why. Any idea?
public Object ConsultaSimpleBD(SqlConnection conexion, String sql)
{
object valor = null;
SqlCommand cmd = null;
SqlDataReader reader = null;
try
{
cmd = new SqlCommand(sql, this.getConexionBD());
reader = cmd.ExecuteReader();
if (reader.Read())
{
valor = reader[0];
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
reader.Close();
}
return valor;
}
ERROR:
************* Exception Text *************
System.NullReferenceException: Object reference not set to an instance of an object. at ControlesGO.Generales.SentenciasBD.ConsultaSimpleBD(SqlConnection conexion, String sql)