BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing Ado Recordsets between methods

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
John Faris
Guest





PostPosted: Thu Jul 21, 2005 3:37 pm    Post subject: Passing Ado Recordsets between methods Reply with quote




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;

Back to top
Vitali Kalinin
Guest





PostPosted: Thu Jul 21, 2005 3:54 pm    Post subject: Re: Passing Ado Recordsets between methods Reply with quote



"John Faris" <johnfaris (AT) nowhere (DOT) com> сообщил/сообщила в новостях следующее:
news:42dfc144$1 (AT) newsgroups (DOT) borland.com...
Quote:

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.
Quote:

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!
Quote:

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



Back to top
John Faris
Guest





PostPosted: Fri Jul 22, 2005 10:42 am    Post subject: Re: Passing Ado Recordsets between methods Reply with quote




Quote:
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



Brilliant! Thanks a lot Vitali that was exactly the problem.

John.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.