重要
从 Windows 8 和 Windows Server 2012 开始,RDS 服务器组件不再包含在 Windows 操作系统中(有关详细信息,请参阅 Windows 8 和 Windows Server 2012 兼容性指南)。 RDS 客户端组件将在将来的 Windows 版本中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 使用 RDS 的应用程序应迁移到 WCF 数据服务。
此示例演示了 InternetTimeout 属性,该属性存在于 DataControl 和 DataSpace 对象上。 在这种情况下,InternetTimeout 属性在 DataControl 对象上演示,超时设置为 20 秒。
// BeginInternetTimeoutCpp
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#import "C:\Program Files\Common Files\System\MSADC\msadco.dll"
#include <ole2.h>
#include <stdio.h>
#include <conio.h>
// Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void InternetTimeOutX(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);
//////////////////////////////////////////////////////////
// //
// Main Function //
// //
//////////////////////////////////////////////////////////
void main()
{
if(FAILED(::CoInitialize(NULL)))
return;
InternetTimeOutX();
::CoUninitialize();
}
//////////////////////////////////////////////////////////
// //
// InternetTimeOutX Function //
// //
//////////////////////////////////////////////////////////
void InternetTimeOutX(void)
{
HRESULT hr = S_OK;
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_RecordsetPtr pRst = NULL;
//Define RDS object pointers
RDS::IBindMgrPtr dc ;
try
{
TESTHR(dc.CreateInstance(__uuidof(RDS::DataControl)));
dc->Server = "https://MyServer";
dc->Connect = "Data Source='AuthorDatabase'";
dc->SQL = "SELECT * FROM Authors";
// Wait at least 20 seconds.
dc->InternetTimeout = 20000;
dc->Refresh();
// Use another Recordset as a convenience
pRst = dc->GetRecordset();
while(!(pRst->EndOfFile))
{
printf("%s %s",(LPSTR) (_bstr_t) pRst->Fields->
GetItem("au_fname")->Value,
(LPSTR) (_bstr_t) pRst->Fields->
GetItem("au_lname")->Value);
pRst->MoveNext();
}
pRst->Close();
}
catch (_com_error &e)
{
PrintProviderError(pRst->GetActiveConnection());
PrintComError(e);
}
}
//////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
//////////////////////////////////////////////////////////
void PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL;
if( (pConnection->Errors->Count) > 0)
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("\t Error number: %x\t%s", pErr->Number,
pErr->Description);
}
}
}
//////////////////////////////////////////////////////////
// //
// PrintComError Function //
// //
//////////////////////////////////////////////////////////
void PrintComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
// EndInternetTimeoutCpp