Ado recordset dataset serialization

Source: Internet
Author: User

As work requires, use ADO to query the database, and then serialize the query records to the memory and transmit them over the network to another machine for deserialization Into A recordset.

For more information, see ipersiststream, istream, olesavetostream, and oleloadfromstream. Well, it's good. The example provided by Ms passes the perfect test ~

The sky is unpredictable. Due to business needs, you must use the variable binding method in the query statement to query the database, instead of combining the query SQL statements. The advantage of this method is that, see here. Because of this requirement, you must use

Command object (the command object can only bind parameters ). For example, see here

However, after the command object executes the execute method, the returned result recordset cannot be serialized. In this case, the recordset object is read-only and cannot be modified. Therefore, an error ("query does not support interfaces") is returned when olesavetostream is called !! This dude is exactly the same as what I 've experienced.

If you are unwilling, you will not stop debugging (debugging and testing), but you will not stop Google

Finally, I found the solution. Because recordset supports open from command, and command is the only way to bind variables, the problem is finally solved by combining the open method of recorset.Code

_ Commandptr cmd; cmd. createinstance ("ADODB. command "); cmd-> activeconnection = pnode-> PCN; cmd-> commandtype = ad1_text; cmd-> commandtext = vssqltext; cstrarrayex spara; spara. splitword (vsparalist, "\ n"); // createparameter append... // append (CMD-> createparameter ("", addouble, adparaminput, 20, (_ variant_t) & spara. getword (I) [1]); _ variant_t affect; // _ recordsetptr PRS = cmd-> execute (& affect, 0, ad1_text); _ recordsetptr PRS; PRS. createinstance (_ uuidof (recordset); PRS-> cursorlocation = aduseclient; PRS-> cursortype = adopendynamic; PRS-> locktype = adlockbatchoptimistic; PRS-> open (idispatch *) CMD, vtmissing, adopenstatic, adlockbatchoptimistic,-1); istreamptr stream; stream. createinstance (_ uuidof (istream); STD: vector <char> Buf; If (savers (PRS, & stream) = s_ OK & streamtomem (stream, Buf ))

Now, we need to consider how to solve the serialization of datasets across platforms. How can this problem be solved? This is an issue worth consideration!

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.