Dbdatareader to read after a while

Asked

Viewed 32 times

1

When the database is at the beginning, it works perfectly, after some time of use, the object does not return anything and the query does not work.

This is the source:

using (DbCommand cmd = CreateCommand(conn, sql.ToString()))
{
    List<TagPojo> tags = new List<TagPojo>();
    AddParameter(cmd, "@tag", DadoTagPojo.Tag);
    AddParameter(cmd, "@dtIni", FData(formataData));
    AddParameter(cmd, "@dtFim", FData(formataData2));


    using (DbDataReader dr = cmd.ExecuteReader())
    {

        while (dr.Read())
        {
            TagPojo tag = new TagPojo();
            ExtrairDados(dr, tag);
            tags.Add(tag);
        }

        return tags;
    }
}
  • In this excerpt I cannot see any reason for this to happen. It may be a problem in what you call this or what is inside ExtrairDados(). It is also difficult to understand what is "the database is in the beginning".

  • It doesn’t even enter while as if the query returns null, but when playing the direct query on the bench, it works. When I said database at the beginning, I meant a new database with little registered information.

  • I had a similar problem in a program that needed to run 24 hours, in the first hours running it worked well, but after a few hours every query returned null and did not generate any error during the search. After a lot of head-breaking I found some topics talking that the problem was the VM that was holding the connections even when you were using Dispose() or it within a using(), so that when you instantiated a new equal connection, He simply repurposed that already created. And then the mistake would happen.

  • Check the connection status and the Connection pool configuration.

  • And how did you solve this, Christian?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.