Resources: HOWTO: Getting ADO Disconnected Recordsets in VBA/C++/Java
SAMPLE: ATL2ADO.exe Returns Disconnected ADO RecordsetIn your project make sure you import dll to create your ADO classes.#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") implementation_only
Next create a method with an [out, retval] property of type _Recordset **
[id(1), helpstring("method GetADORecordset")] HRESULT GetADORecordset( [out, retval] _Recordset **ppRecordset);
Your source code should look something like this:
STDMETHODIMP CReturnADO::GetADORecordset(_Recordset **ppRecordset)
{
_ConnectionPtr pConnection;
_RecordsetPtr pRecordset;
try
{
pConnection.CreateInstance(__uuidof(Connection));
pConnection->CursorLocation = adUseClient; // Important for disconnected sets
pConnection->Open("DSN=SQLSource","loginnmae","password",-1);
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset->CursorLocation = adUseClient; // Important for disconnected sets
pRecordset->PutRefActiveConnection(pConnection.GetInterfacePtr()); // Associate the connection to this recordset pRecordset->Open("SELECT DISTINCT name FROM TBLWHATEVER WHERE name IS NOT NULL",vtMissing,
adOpenForwardOnly, adLockReadOnly,
adCmdText); pRecordset->PutRefActiveConnection(NULL); // Disassociate the connection from the recordset. if(pConnection->GetState() == adStateOpen)
pConnection->Close();
pConnection = NULL;
*ppRecordset = pRecordset.Detach(); }
catch(_com_error *e)
{
return AtlReportError(CLSID_ReturnADO,e->ErrorMessage(),IID_IReturnADO,E_FAIL);
}
catch(...)
{
return AtlReportError(CLSID_ReturnADO,"Unknown Error.",IID_IReturnADO,E_FAIL);
} return S_OK;
}
SAMPLE: ATL2ADO.exe Returns Disconnected ADO RecordsetIn your project make sure you import dll to create your ADO classes.#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") implementation_only
Next create a method with an [out, retval] property of type _Recordset **
[id(1), helpstring("method GetADORecordset")] HRESULT GetADORecordset( [out, retval] _Recordset **ppRecordset);
Your source code should look something like this:
STDMETHODIMP CReturnADO::GetADORecordset(_Recordset **ppRecordset)
{
_ConnectionPtr pConnection;
_RecordsetPtr pRecordset;
try
{
pConnection.CreateInstance(__uuidof(Connection));
pConnection->CursorLocation = adUseClient; // Important for disconnected sets
pConnection->Open("DSN=SQLSource","loginnmae","password",-1);
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset->CursorLocation = adUseClient; // Important for disconnected sets
pRecordset->PutRefActiveConnection(pConnection.GetInterfacePtr()); // Associate the connection to this recordset pRecordset->Open("SELECT DISTINCT name FROM TBLWHATEVER WHERE name IS NOT NULL",vtMissing,
adOpenForwardOnly, adLockReadOnly,
adCmdText); pRecordset->PutRefActiveConnection(NULL); // Disassociate the connection from the recordset. if(pConnection->GetState() == adStateOpen)
pConnection->Close();
pConnection = NULL;
*ppRecordset = pRecordset.Detach(); }
catch(_com_error *e)
{
return AtlReportError(CLSID_ReturnADO,e->ErrorMessage(),IID_IReturnADO,E_FAIL);
}
catch(...)
{
return AtlReportError(CLSID_ReturnADO,"Unknown Error.",IID_IReturnADO,E_FAIL);
} return S_OK;
}
这是用COM返回记录集,而我需要的是如何用TCP/IP返回检索到的记录集,不过谢谢to jeffchen(眨)
你说的意思是把记录集寸放到XML文件,然后用TCP/IP发送这个文件吧,速度如何?有源代码吗?