Suppose that you have code something like this:
SqlConnection con = new SqlConnection(myConnectionString);
SqlCommand cmd = new SqlCommand("SQL STATEMENT");
con.Open();
cmd.ExecuteReader();
well, in this peace of code your command object doesn't know anything about your connection. To fix this create your command object like this:
SqlCommand cmd = new SqlCommand("SQL STATEMENT", con);
or if you use empty constructor or don't set connection property in costructor assign connection as property:
cmd.Connection = con;