title: Why is DataReader giving "Enumeration Yielded No Results"?
body: <p>I am using a very simple stored procedure that has 2 parameters. It then fills up a DataReader, but when I run the code, the DataReader throws an error saying "Enumeration yielded no results" despite making it past the reader.Read() line. </p>
  
  <p>My function is passed email as a parameter. It then establishes the connection:</p>
  
  <pre><code>SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["IdesignTriviaConnection"].ConnectionString);
              SqlCommand cmd = new SqlCommand("usp_GetCurrentLink", con);
              SqlDataReader reader;
  
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@date", SqlDbType.DateTime, 100).Value = DateTime.Today;
              cmd.Parameters.Add("@email", SqlDbType.VarChar, 100).Value = email;
  </code></pre>
  
  <p>After this it opens the connection and establishes the reader:</p>
  
  <pre><code>try
              {
                  if (cmd.Connection.State == ConnectionState.Closed)
                  {
                      cmd.Connection.Open();
                  }
                  reader = cmd.ExecuteReader();
  
                  while (reader.Read())
                  {
                      long LinkID = reader.GetInt32(0);
                      String URL = reader.GetString(1);
                      long Completed = reader.GetInt32(2);
  
  if (LinkID == 0)
                      {
                          link = "0";
                      }
                      else
                      {
                          if (Completed == 1)
                          {
                              link = "1";
                          }
                          else
                          {
                              link = URL;
                          }
                      }
                  }
  </code></pre>
  
  <p>As stated, the stored procedure works perfectly in query analyzer and I've even used the debugger to see that it is actually returning the expected values of:</p>
  
  <p>So where am I going wrong here? Why, if the datareader is failing to enumerate any data, is it making it past the reader.Read() line? Why am I am I able to see that data in the debugger if I so choose?</p>