Hi,
I am migrating some code from Java/JSP to C#/.NET.
One of my files is an ImageServlet, this basically retrieves a BLOB Image
from a database and displays it directly to the response output. In this
way, I can dynamically display images throughout my application.
However the code I have migrated seems to work intermittently, it will work
the first two or three times then freeze and stop working.
Perhaps its an issue with the database connection? Can anyone shed any
light - the code is included below:
Regards,
Peter Dolukhanov
--
protected virtual void process (HttpRequest request, HttpResponse response)
{
OleDbCommand ps = conn.CreateCommand ();
ps.CommandText = sql;
OleDbDataReader rs = ps.ExecuteReader ();
if (rs.Read ())
{
BinaryWriter bw = new BinaryWriter(response.OutputStream);
int startIndex = 0;
int bufferSize = 1024;
byte[] bt = new byte[bufferSize];
long c;
while ( (c = rs.GetBytes(0, startIndex, bt, 0, bufferSize)) > 0)
{
bw.Write(bt, 0, (int)c);
startIndex += bufferSize;
}
bw.Flush();
bw.Close();
rs.Close ();
conn.Close();
response.Flush();
response.Close ();
}
}
}