RDA执行pull操作时会失败,[,,,Database name,,],希望高手帮帮我,代码如下
[复制链接]
void CRDAExamDlg::OnBtnPull()
{
ISSCERDA * pCERDA = NULL;
BSTR bstrConnectStr;
BSTR bstrLocalConnectStr;
BSTR bstrLocalTableName;
BSTR bstrQueryStr;
BSTR bstrErrorTableName;
RDA_TRACKOPTION trackOption;
//CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_RemoteDataAccess, NULL, CLSCTX_INPROC_SERVER, IID_ISSCERDA, (LPVOID *) &pCERDA);
//ASSERT(S_OK == hr);
//ASSERT(pCERDA);
if (S_OK == hr)
{
MessageBox(L"CoCreateInstance OK!", L"Tip", MB_OK);
}
else if (REGDB_E_CLASSNOTREG == hr)
{
/*char szText[50] = {0};
wsprintf((unsigned short *)szText, L"CoCreateInstance failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);*/
MessageBox(L"A specified class is not registered in the registration database!", L"Tip", MB_OK);
}
else if (CLASS_E_NOAGGREGATION == hr)
{
/*char szText[50] = {0};
wsprintf((unsigned short *)szText, L"CoCreateInstance failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);*/
MessageBox(L"This class cannot be created as part of an aggregate!", L"Tip", MB_OK);
}
else
{
MessageBox(L"CoCreateInstance failed!", L"Tip", MB_OK);
}
//设置Internet URL
BSTR bstr = NULL;
bstr = SysAllocString(CString("Http://winner/sqlce/sscesa20.dll"));
hr = pCERDA->put_InternetURL(bstr);
if (S_OK == hr)
{
MessageBox(L"put_InternetURL OK!", L"Tip", MB_OK);
}
else
{
char szText[50] = {0};
wsprintf((unsigned short *)szText, L"put_InternetURL failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);
}
SysFreeString(bstr);
//设置Internet UserName
bstr = SysAllocString(CString(""));
hr = pCERDA->put_InternetLogin(bstr);
if (S_OK == hr)
{
MessageBox(L"put_InternetLogin OK!", L"Tip", MB_OK);
}
else
{
char szText[50] = {0};
wsprintf((unsigned short *)szText, L"put_InternetLogin failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);
}
SysFreeString(bstr);
//设置Internet Password
bstr = SysAllocString(CString(""));
hr = pCERDA->put_InternetPassword(bstr);
if (S_OK == hr)
{
MessageBox(L"put_InternetPassword OK!", L"Tip", MB_OK);
}
else
{
char szText[50] = {0};
wsprintf((unsigned short *)szText, L"put_InternetPassword failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);
}
SysFreeString(bstr);
//设置服务器连接串
bstrConnectStr = SysAllocString(CString("Provider=sqloldb;data source=winner;Initail Catalog=dbtest;user=;password="));
//设置本地数据库连接串
bstrLocalConnectStr = SysAllocString(CString("Provider=microsoft.sqlserver.oledb.ce2.0;Data Source=\\My Documents\\MyDB.sdf"));
hr = pCERDA->put_LocalConnectionString(bstrLocalConnectStr);
if (S_OK == hr)
{
MessageBox(L"put_LocalConnectionString OK!", L"Tip", MB_OK);
}
else
{
char szText[50] = {0};
wsprintf((unsigned short *)szText, L"put_LocalConnectionString failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);
}
SysFreeString(bstrLocalConnectStr);
//设置本地表名
bstrLocalTableName = SysAllocString(CString("students"));
//设置查询的SQL语句
bstrQueryStr = SysAllocString(CString("select * form students"));
//设置跟踪
trackOption = TRACKINGOFF;
//获取服务器数据
if (SUCCEEDED(pCERDA->Pull(bstrLocalTableName,
bstrQueryStr,
bstrConnectStr,
trackOption,
/*bstrErrorTableName*/NULL)))
{
MessageBox(L"Pull OK!", L"Tip", MB_OK);
}
else
{
/*char szText[50] = {0};
wsprintf((unsigned short *)szText, L"Pull failed! Code: %d", GetLastError());
MessageBox((unsigned short *)szText, L"Tip", MB_OK);
*/
ISSCEErrors * pISSCEErrors = NULL;
if (SUCCEEDED(pCERDA->get_ErrorRecords(&pISSCEErrors)))
{
ShowErrors(pISSCEErrors);
pISSCEErrors->Release();
}
}
SysFreeString(bstrConnectStr);
SysFreeString(bstrLocalTableName);
SysFreeString(bstrQueryStr);
pCERDA->Release();
}