I executed same code on my test application. It gives me same result in application as well in sql.
it provides me the same result. Only the thing i changed in your code is :
1. SqlCommand comm = new SqlCommand(query,
conn); : instead of string variable i put the object of SqlConnection conn.
2. conn.Open()
3. conn.Close()
as mentioned below :
string con = ConfigurationSettings.AppSettings["DBConnectionString"];
SqlConnection conn = new SqlConnection(con);
conn.Open();
string query = "select name from sysdatabases(nolock)";
SqlCommand comm = new SqlCommand(query, conn);
SqlDataReader dr = comm.ExecuteReader();
conn.Close();