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());
}