Error implementation of this object can cause a memory leak or one of the following errors:
The operation requested by the application isn't allowed if the object is closed.
Or
Type mismatch
Or
Error ' ASP 0115 '-A trappable error occured in A external object
More information
Use the following steps to implement a method that returns a recordset from a Visual C + + COM object to the Active Server Pages. 1. Create an ATL DLL project named "Passrs". 2. Insert an ATL object named "Passrsobj". 3. Add methods that contain the following information: Method Name:testmethod
Parameters: [out, retval] lpdispatch* pprecordset
4. Include the following line in the object's implementation file:#import "msado15.dll" no_namespace rename("EOF", "adoEOF")
5. Implement the method as follows:
Note: You must first change the uid=<username> and Pwd=<strong password> to the correct values before you can run this code. Make sure that the UID has the appropriate permissions required to perform this operation in the database.
stdmethodimp Cpassrsobj::testmethod (lpdispatch *pprecordset)
{
_connectionptr pconn;
_RecordsetPtr PRs;
Pconn.createinstance (__uuidof (Connection));
Prs.createinstance (__uuidof (Recordset));
Pconn->open ("dsn=pubs;uid=<username>;p wd=<strong password>;", (BSTR) null, (BSTR) NULL,-1);
//client side cursor is required for disconnected recordsets
prs->cursorlocation = adUseClient;
Prs->open ("SELECT * from authors",
Pconn.getinterfaceptr (),
adOpenKeyset, adLockOptimistic, 1 );
//Disconnect the recordset
Prs->putrefactiveconnection (NULL);
Clone the recordset.
//note:recordset to is cloned must support bookmarks
Prs->clone (adlockoptimistic)->queryinterface (iid_ IDispatch, (void**) pprecordset);
Prs->close ();
Pconn->close ();
PRs = NULL;
Pconn = NULL;
return S_OK;
}
6. Create an ASP page that contains the following code:
<%
Dim rsTest, oTestPassRs
Set oTestPassRs = Server.CreateObject("PassRs.PassRsObj")
Set rsTest = oTestPassRs.TestMethod()
Do
Response.Write ( "Value in Record = " & rsTest(1) & "<BR>" )
rsTest.MoveNext
Loop until rsTest.EOF
rsTest.Close
Set rsTest = Nothing
Set oTestPassRs = Nothing
%>