Reputation: 947
Is there a way to make multiple TADOQuery have access to the same session or transaction information?
Both TADOQuery have the same TADOCOnnection, but that doesn't work.
Example - I have one query that generates a temp table, I want to use that temp table in another query, but when I try, it doesn't know about the temp table.
procedure Foo(dbCon : TADOConnection);
var
q1 : TADOQuery; //TODO : set your ADOQuery to use a forward only read only cursor.
q2 : TADOQuery;
begin
q1 := TADOQuery.Create(nil);
q1.Connection := dbCon;
q1.SQL.Text := 'SELECT id INTO #TempT FROM dFTNodes;';
q1.Active := true;
q2 := TADOQuery.Create(nil);
q2.Connection := dbCon;
q2.SQL.Text := 'SELECT id FROM #TempT;';
q2.Active := true; //Fails here does not know table #TempT
end;
Upvotes: 0
Views: 711
Reputation: 27367
If your TADOConnection is not defined to KeepConnection=True
, which is default,
the connection is dropped after executing of q1, your session is lost and #TempT is gone.
In general if there are no living TCustomAdodatasets using the connection a connection using KeepConnection=False
will be closed.
q2 will get a new session and not be able to access #TempT.
Upvotes: 3