Extracted from the EVC advanced programming and application development book, we can use hresult hR = noerror;
Isscerda * pcerda = NULL;
BSTR = NULL;
BSTR bconnectstr = NULL;
BSTR bquerystr = NULL;
BSTR blocalconnectstr = NULL;
BSTR blocaltablename = NULL;
BSTR berrortablename = NULL;
Rda_trackoption trackoption = trackingoff; HR = coinitializeex (null, coinit_multithreaded); // You must initialize the COM interface first.
HR = cocreateinstance (clsid_remotedataaccess, null, clsctx_inproc_server, iid_isscerda, (lpvoid *) & pcerda );
Assert (hR = s_ OK );
Assert (pcerda! = NULL );
// Set the Internet URL
BSTR = sysallocstring (_ T ("http: // host address/virtual path/sscesaw.dll"); // The host address must use an IP address instead of a computer name.
Pcerda-> put_interneturl (BSTR );
Sysfreestring (BSTR); // set Internet Username
BSTR = sysallocstring (_ T (""));
Pcerda-> put_internetlogin (BSTR );
Sysfreestring (BSTR); // sets the internet password
BSTR = sysallocstring (_ T (""));
Pcerda-> put_internetpassword (BSTR );
Sysfreestring (BSTR); trackoption = trackingoff; // set the name of the error table.
Berrortablename = sysallocstring (_ T ("tblerrors "));
// Set the server connection string
Bconnectstr = sysallocstring (_ T ("provider = sqloledb; Data Source = Host address; initial catalog = database name; user id = sa; Password = 123 ")); // It is best to set SQL Server to the mode of SQL Server and Windows mutual authentication and set a password
// Set the connection string of the local database
Blocalconnectstr = sysallocstring (_ T ("provider = Microsoft. sqlserver. oledb. ce.2.0; Data Source = // database name on my documents // PDA. SDF "); // The first-mover event first creates an empty database on isqlw20.exe installed on PDA. Do not create a table; otherwise, an error occurs. It is recommended that you check whether the suffix SDF exists after creation.
Pcerda-> put_localconnectionstring (blocalconnectstr );
Sysfreestring (BSTR );
// Set the local table name
Blocaltablename = sysallocstring (local table name); // This table must not exist beforehand. Otherwise, an error occurs.
// 9. Set the query SQL statement
Bquerystr = sysallocstring (_ T ("select * from table name on SQL Server "));
// Obtain server data
HR = pcerda-> pull (blocaltablename, bquerystr, bconnectstr, trackoption, berrortablename );
If (succeeded (HR ))
{
Afxmessagebox (_ T ("OK "));
}
Else
{
Issceerrors * pissceerrors = NULL;
If (succeeded (hR = pcerda-> get_errorrecords (& pissceerrors )))
{
Showerrors (pissceerrors); // This is an easy-to-find error, which is listed below
Pissceerrors-> release ();
}
}
// Release the remote access interface
Pcerda-> release (); void showerrors (issceerrors * pissceerrors)
{
Hresult hr;
Long cbbuf;
Long I;
Long lerrorcount;
Long lerrorindex;
Long lparamcount;
Long lparamindex;
Variant var;
Variant varparam;
Wchar wszbuff [4096];
Wchar * pwszbuffpos = & wszbuff [0];
BSTR;
Issceerror * pissceerror = NULL;
Issceparams * pissceparams = NULL;
Issceparam * pissceparam = NULL;
Bool fsuccess = false;
// Initialize the variable
Variantinit (& var );
Variantinit (& varparam );
// Obtain the number of errors through the iissceerrors Interface
If (failed (hR = pissceerrors-> get_count (& lerrorcount )))
Goto exit;
If (lerrorcount <= 0)
{
: MessageBox (null, l "no error message", l "Display error", mb_ OK );
Fsuccess = true;
Goto exit;
}
// Use the pop-up dialog box to display each error.
For (lerrorindex = 0; lerrorindex <lerrorcount; lerrorindex ++)
{
Cbbuf = swprintf (pwszbuffpos, l "error % d of % d/R/N ",
Lerrorindex + 1, lerrorcount );
Pwszbuffpos + = cbbuf;
// Get error records
Var. Vt = vt_i4;
Var. lval = lerrorindex;
If (failed (hR = pissceerrors-> get_item (VAR, & pissceerror) goto exit;
// Use the pop-up box to display the error message
: MessageBox (null, wszbuff, l "error", mb_ OK );
Fsuccess = true;
Exit:
// Release the error parameter object
If (pissceparam)
{
Pissceparam-> release ();
Pissceparam = NULL;
}
// Release the error parameter set object
If (pissceparams)
{
Pissceparams-> release ();
Pissceparams = NULL;
}
// Release the error object
If (pissceerror)
{
Pissceerror-> release ();
Pissceerror = NULL;
}
// If an error message fails to be obtained
If (! Fsuccess)
{
: MessageBox (null, l "failed to get error message! ", L" Display error ", mb_ OK );
}
Return;
}
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.