To resolve the length limit for the text, image type fields of SQL Server

Source: Internet
Author: User

when SQL Server is installed by default, the TEXT, NTEXT, and Image type fields have a length limit, and if you write more data than the limit throws an exception, the default length limit is 65536 and you need to modify the global configuration parameters of the database:

exec sp_configure ' max text repl size (B) ', ' 655360 '--adjustment length limit of 655360, increase 10 times times
reconfigure--make configuration effective

string objdata;
....... (The preparation of objdata data is omitted)

//Build a secure array
Const LONG Lweishu = 1;//safe array dimension
BYTE *pbyte;
SAFEARRAY far* PSA;
Safearraybound Rgsabound[lweishu];
rgsabound[0].llbound = 0;
rgsabound[0].celements = Objdata.length ();

PSA = SafeArrayCreate (VT_UI1, Lweishu, rgsabound);
if (Safearrayaccessdata (PSA, (void * *) &pbyte) = = NOERROR)
{
//Copy object data into a safe array
memcpy (Pbyte,&objdata[0],objdata.length ());
}
safearrayunaccessdata (PSA);

VARIANT Vararray;
VARARRAY.VT = Vt_array | VT_UI1;
vararray.parray = PSA;

//Update the data to the database.
fieldptr fieptr = Objrcrecordset->fields->getitem (_variant_t ("FieldName"));
Fieptr->appendchunk (vararray);
variantclear (&vararray);
///////////////////////////////////////////////////////////////
The above is available in the case of AddNew.
if the parameter of the stored procedure has text, image, and so on. The following section of the above code is changed to
storeprocparamobj->value = Vararray;
/////////////////////////////////////////////////////////////
also
You can use the _variant_t object instead of directly using the VARIANT structure, which automatically releases the data at the time of destruction. The latter requires
call VariantClear yourself to clean up.



The above code applies to text, the Image field type, and is tested. (ADO, VC6, Win2000, sqlserver2000)

---------------------------------------------------------------------------

Ikon Digital http://shop108303530.taobao.com

 JQZCSBZ
Source:http://www.cnblogs.com/ZengSir/ 
email:763754930@qq. com 
QQ Communication:763754930

More information, it tips, incurable diseases and so on can pay attention to the Ikon of the public number.

To resolve the length limit for the text, image type fields of SQL Server

Related Article

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.