Re: Passing Ado Recordsets between methods



"John Faris" <johnfaris@xxxxxxxxxxx> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:42dfc144$1@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> Hi all.
>
> I have been fighting this one for some time. I am trying to pass an Ado
recordset between two methods in a COM+ object. The recordset is created by
opening a TAdoStoredProc which is created dynamically within one of the
methods and calls an SQL Server stored procedure.
>
> It all seems to work apart from the fact that when the method that called
the sp executing method gets the recordest back it is in a closed state.
Hopefully the following simplified code will help make my problem clearer.
Any help would be great as I am stumped!
>
> TIA .
>
> procedure TMyClass.Method1;
> var
> RecSet: RecordSet20;
> begin
> GetRecSet(RecSet);
> // RecSet is closed here! WHY?????
> end;
>
> procedure TMyClass.GetRecSet(out Recset: RecordSet20);
> var
> SP: TADOStoredProc;
> CONN: TADOConnection;
> begin
> CONN := TADOConnection.Create(nil);
> try
> CONN.ConnectionString := 'MyConnectionString';
> CONN.CursorLocation := clUseServer;
> CONN.LoginPrompt := False;
> CONN.Open;
> SP := TADOStoredProc.Create(nil);
> try
> SP.Connection := CONN;
> SP.LockType := ltReadonly;
> SP.CursorType := ctStatic;
> SP.CursorLocation := clUseClient;
> SP.ProcedureName := 'MyProcName';
> SP.Open;
> //copy the recordset into our output parameter
> Recset := SP.Recordset.Clone(adLockUnspecified);
> //RecSet is open here!
> finally
> SP.Free;
> end;
> finally
> CONN.free;
> end;
> end;
>
As soon as you are closing connection (which is implemented inside
TADOConnection.Destroy) all connected Recordsets (and it's clones) became
closed. So if you want them to be Active you should disconnect the first.

Regards,
Vitali


.



Relevant Pages

  • to show a recordset as table
    ... Set recSet = New ADODB.Recordset ... .CursorType = adOpenKeyset ... After this code I correctly bind the recordset to the form, ...
    (comp.databases.ms-access)
  • to show a recordset as table
    ... Set recSet = New ADODB.Recordset ... .CursorType = adOpenKeyset ... After this code I correctly bind the recordset to the form, ...
    (microsoft.public.access.modulesdaovba)
  • RE: Creaet XML file from recordset
    ... RecordSet creating the xml file from the returned field names and values, ... 'Create and Open ur RecSet ... > thanks - shachar. ...
    (microsoft.public.vb.general.discussion)
  • multiple query problem
    ... I open a connection, open a recordset, fetch data, close ... var adLockOptimistic = 3; ... JOIN (CountryISO INNER JOIN (CurrencyISO INNER JOIN ON ...
    (microsoft.public.data.ado)
  • Re: Reapplying successfull batch updates
    ... > A cloned TadoDataset keeps its own set of updated ... > current value after a batchupdate to the source Dataset. ... AdoRS: Recordset; ...
    (borland.public.delphi.database.ado)