Comparison of two database binary field access control methods

Source: Internet
Author: User
Tags bool comparison tostring
Binary | control | data | Database mode one: for small volumes of data, a load of memory, one-time access
<summary>
Small capacity attachment data read performance test
</summary>
<param name= "strSQL" ></param>
<returns></returns>
public static bool Processdatafromdatabasebyadapter (string Strsql,out string strerr)
{
Long T0 = Environment.tickcount;
DataTable table;
if (! Oledatabaseproxy.executesql (strsql,out table,out strerr)) return false;
Long Imagedatasizecount = 0;
if (! Capabilityproxy.processdatafromdatabase (ref table,out imagedatasizecount,out Strerr)) return false;
Long T1 = Environment.tickcount;
Logproxy.writelog ("Database performance test: Total time consuming" + convert.tostring (t1-t0) + "MS, data Volume:" + imagedatasizecount.tostring () + "bytes");
Strerr = "";
return true;
}
<summary>
Performing a data query operation
</summary>
<param name= "strSQL" ></param>
<param name= "Table" ></param>
<param name= "Strerr" ></param>
<returns></returns>
public static bool ExecuteSQL (string strsql,out System.Data.DataTable table,out string strerr)
{

System.Data.OleDb.OleDbConnection Cnn = new OleDbConnection ();
cnn.connectionstring = Configproxy.getvaluebykey ("oleconnectionstring");
System.Data.OleDb.OleDbDataAdapter adapter = new OleDbDataAdapter (STRSQL,CNN);
Table = new System.Data.DataTable ();
Try
{
Adapter. Fill (table);
}
catch (Exception ERR)
{
Strerr = Err.message;
return false;
}
Strerr = "";
Releasing resources
Cnn.dispose ();
Adapter. Dispose ();
Gc. Collect ();
return true;
}
<summary>
Processing database records
</summary>
<param name= "Table" ></param>
<param name= "Imagedatasizecount" ></param>
<param name= "Strerr" ></param>
<returns></returns>
private static bool Processdatafromdatabase (ref DataTable table,out long imagedatasizecount,out string strerr)
{
Imagedatasizecount = 0;
for (int i = 0;i < table. Rows.count;i + +)
{
byte [] imagecontent = (byte[]) table. rows[i]["attachment content"];
Imagedatasizecount + = convert.toint64 (table. rows[i]["attachment capacity"]);
Capabilityproxy.processimagedata (ref imagecontent);
}
Strerr = "";
return true;
}

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.


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.