does opening TMyQuery automatically open TMyConnection?
Posted: Fri 15 May 2020 09:17
When running a query using TMyQuery, do I need to explicitly open (and close) the TMyConnection as well as the query or will the query open the connection for me if it is currently closed?
I'd prefer to keep the connection open all the time but just in case I somewhere previously had issued
is it OK to just say
or must I say
or even more complicated, if I don't know the current connection state,
I'd prefer to keep the connection open all the time but just in case I somewhere previously had issued
Code: Select all
MyConnection1.Close;
Code: Select all
MyQuery.Close;
MyQuery.SQL.Clear;
MyQuery.SQL.Add(sql);
MyQuery.Open;
...
MyQuery.Close;
or must I say
Code: Select all
MyQuery.Close;
MyQuery.SQL.Clear;
MyQuery.SQL.Add(sql);
MyConnection1.Open; // <-------------
MyQuery.Open;
...
MyQuery.Close;
MyConnection1.Close;
Code: Select all
DatabaseConnectionState := MyConnection1.Connected; //remember state
MyQuery.Close;
MyQuery.SQL.Clear;
MyQuery.SQL.Add(sql);
MyConnection1.Open; // <-------------
MyQuery.Open;
....
MyQuery.Close;
MyConnection1.Connected := DatabaseConnectionState;