Parsing Issues

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a program that runs as a windows service waking up at predefined
intervals to send out mails. Each mail is based on a template with tags to
replace with database data from that specific row (mail merge type of
operation). Every so often the parsing is only half-done; but I’ve seen the
parsing work fully some times. I was thinking it could be some kind of a
memory problem (there are a lot of string manipulations in the code) but
checked to find the server did have good amount of free memory available. Has
anyone come across such a problem? If so, was this problem circumvented and
how?

I am adding below code snippet of how I am accomplishing the same.
try
{
SqlConnection con = dbc.Connection;
SqlConnection con1 = dbc.Connection;
SqlCommand com = new SqlCommand("<db select for the master row>", con);
SqlCommand com1;
SqlDataReader sdr = com.ExecuteReader();

while (sdr.Read())
{
string temp = shipmailtemplate;

temp = temp.Replace("<#tagidentifier>", sdr.GetSqlString(3).ToString());
….<more replacements such as above)

com1 = new SqlCommand("<db select for the detail row>", con1);

SqlDataReader sdr1 = com1.ExecuteReader();
bool isrow = false;
while (sdr1.Read())
{
isrow = true;
iter = iter.Replace("<#tagidentifier>", sdr1.GetSqlString(0).ToString());
….<more replacements such as above)
}
sdr1.Close();

if (isrow)
{
<send mails out>
}
}
sdr.Close();
con1.Close();
con.Close();
}
catch (Exception ex)
{
WriteError(ex.ToString());
}
 
Badri,

How does the "dbc.Connection" property behave? Does it always return
the same connection, or does it create a new connection each time it
is called? If it always returns the same connection, then this code
may be the source of your problems:

SqlConnection con = dbc.Connection;
SqlConnection con1 = dbc.Connection;

If dbc.Connection always returns the same connection, then con and
con1 both point to the same connection. SqlDataReader requires
exclusive access to a connection until it is closed.
 
Chris - Thx for your response; the dbc.Connection always returns a new
connection. The curious thing about this is that it sometimes is able to
parse even 250 mails successfully but other times it even fails with just 60
to 70 parsings. And out of these failures, 99% it does not retrieve the
detail records (the second SQL / inner loop) in spite of the bool variable
"isrow" being checked prior to sending out the mails and no exception is
thrown either.

thx
 
Chris - Thx for your response; the dbc.Connection always returns
a new connection. The curious thing about this is that it
sometimes is able to parse even 250 mails successfully but other
times it even fails with just 60 to 70 parsings. And out of
these failures, 99% it does not retrieve the detail records (the
second SQL / inner loop) in spite of the bool variable "isrow"
being checked prior to sending out the mails and no exception is
thrown either.

Badri,

The only other thing I can think of is the connection may be timing
out. You could try using DataSets instead of data readers. That
would reduce the time a connection remains open.
 
Back
Top