Mode two: online, according to the specified size of the segment to get
<summary>
Reading performance test of bulk attachment data
</summary>
<param name= "strSQL" ></param>
<returns></returns>
public static bool Processdatafromdatabasebyreader (string Strsql,out string strerr)
{
Long T0 = Environment.tickcount;
Long Imagedatasizecount = 0;
System.Data.OleDb.OleDbCommand cmd = new OleDbCommand ();
OleDbConnection Cnn = new OleDbConnection (Configproxy.getvaluebykey ("oleconnectionstring"));
Cmd. Connection = Cnn;
Cmd.commandtext = strSQL;
OleDbDataReader reader;
Open connection
Try
{
Cnn.open ();
}
catch (Exception ERR)
{
Strerr = Err.message;
return false;
}
byte[] pixels = new Byte[numpixels];
Long readcount = 0;
reader = cmd. ExecuteReader ();
Process-by-article
while (reader. Read ())
{
for (long i = 0; i< convert.toint64 reader. GetString (7)); i = i + numpixels)
{
Readcount = reader. GetBytes (6,i,pixels,0,numpixels);
if (readcount = 0)
{
Break
}
else if (Readcount = = numpixels)
{
Processimagedata (ref pixels);
}
Else
{
Byte[]buff = new Byte[readcount];
Processimagedata (ref buff);
}
Imagedatasizecount + = Readcount;
}
}
Reader. Close ();
Close connection
if (cnn.state = = System.Data.ConnectionState.Open)
{
Cnn.close ();
}
Long T1 = Environment.tickcount;
Logproxy.writelog ("Database performance test: Total time consuming" + convert.tostring (t1-t0) + "MS, data Volume:" + imagedatasizecount.tostring () + "bytes");
Releasing resources
Cnn.dispose ();
Cmd. Dispose ();
Gc. Collect ();
Strerr = "";
return true;
}
<summary>
Buffer size
</summary>
public static int numpixels = Int. Parse (Configproxy.getvaluebykey ("buffersize"));
<summary>
Processor Latency
</summary>
public static int processimagerepeats = Int. Parse (Configproxy.getvaluebykey ("Cpulatetime"));
Comparison of two ways:
The first way: Reduce database pressure, data size known
The second way: increase database pressure, unknown data size
Summarize:
According to the actual application of the choice, in the binary field content size is known, the database burden pressure than the case to choose the first way; in the case of the binary field, the content size is unknown, and the database burden is less stressful, choose the second way.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.