Just remove one line from code that is con.Close() because SqlDataReader works in connected mode and it read forward only mode.
using System;
using System.Data.SqlClient;
namespace RestApp
{
class Program
{
public static void Main(string[] args)
{
SqlDataReader dr = Program.hello("select top 10 firstName,lastName from DimCustomer");
while (dr.Read())
{
Console.WriteLine(dr.GetValue(0));
}
Console.ReadLine();
}
public static SqlDataReader hello(string query)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=adventure_works;Integrated Security=true;");
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
con.Close();
return dr;
}
}
}