Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Temp Connection, FireDAC, D10



Permlink Replies: 2 - Last Post: Feb 3, 2016 8:18 PM Last Post By: Lajos Juhasz
Jim Sawyer

Posts: 214
Registered: 1/3/10
Temp Connection, FireDAC, D10
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 1:08 PM
I have been trying on and off for two weeks to learn to do a
temporary connection with FireDAC and MySQL. I have the
following code:

procedure TfrmTemp.FormShow(Sender: TObject);
var
TempConnection: TFDConnection;
Query: TFDQuery;
begin
TempConnection := TFDConnection.Create( NIL );
Query := TFDQuery.Create( TempConnection );
Query.ResourceOptions.ParamCreate := false;
Query.Connection := TempConnection;
Query.Open( 'DriverID=MySQL;DataBase=VetTest;User_Name=root;password=spyke;port=3306' );
with Query.Params do
begin
Clear;

end;
end;

When I execute the

Query.Open(...

statement I get the error

[FireDAC][Comp][Clnt]-512. Connection is not defined for []. Possible reason: Connection and
ConnectionName are both empty.

I cannot find out what I'm doing incorrectly. I Dropped a TFDConnection component and a
TFDQuery component onto a form and hooked them up and made them work and compared
their parameters with those used in the temporary connection. I cannot find a difference.

Can someone please shed some light on this problem?

Thanks,
Jim Sawyer

Edited by: Jim Sawyer on Feb 3, 2016 2:07 PM
Jim Sawyer

Posts: 214
Registered: 1/3/10
Re: Temp Connection, FireDAC, D10
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 2:10 PM   in response to: Jim Sawyer in response to: Jim Sawyer
I finally made it work by the following code:

procedure TfrmTemp.FormShow(Sender: TObject);
var
TempConnection: TFDConnection;
Query: TFDQuery;
begin
TempConnection := TFDConnection.Create( NIL );
with TempConnection.Params do
begin
Clear;
Add('DriverID=MySQL');
Add('DataBase=VetTest');
Add('User_Name=root');
Add('password=spyke')
end;
TempConnection.Connected := true;
Query := TFDQuery.Create( TempConnection );
Query.ResourceOptions.ParamCreate := false;
Query.Connection := TempConnection;
Query.SQL.BeginUpdate;
try
Query.SQL.Add('select * from client');
finally
Query.SQL.EndUpdate;
end;
Query.Open;
Query.First;
ShowMessage( Query.FieldValues['LastName'] );
Query.Edit;
Query.FieldValues['LastName'] := 'ADAMS/BERRYMAN';
Query.Post;
ShowMessage( Query.FieldValues['LastName'] );
Query.Close;
end;

My question now, is what is the proper code for getting rid
of the temporary connection and query after I'm through with
them?

Thanks,
Jim Sawyer


Jim Sawyer wrote:

I have been trying on and off for two weeks to learn to do a
temporary connection with FireDAC and MySQL. I have the
following code:

procedure TfrmTemp.FormShow(Sender: TObject);
var
TempConnection: TFDConnection;
Query: TFDQuery;
begin
TempConnection := TFDConnection.Create( NIL );
Query := TFDQuery.Create( TempConnection );
Query.ResourceOptions.ParamCreate := false;
Query.Connection := TempConnection;
Query.Open( 'DriverID=MySQL;DataBase=VetTest;User_Name=root;password=spyke;port=3306' );
with Query.Params do
begin
Clear;

end;
end;

When I execute the

Query.Open(...

statement I get the error

[FireDAC][Comp][Clnt]-512. Connection is not defined for []. Possible reason: Connection and
ConnectionName are both empty.

I cannot find out what I'm doing incorrectly. I Dropped a TFDConnection component and a
TFDQuery component onto a form and hooked them up and made them work and compared
their parameters with those used in the temporary connection. I cannot find a difference.

Can someone please shed some light on this problem?

Thanks,
Jim Sawyer

Edited by: Jim Sawyer on Feb 3, 2016 2:07 PM
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Temp Connection, FireDAC, D10
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 3, 2016 8:18 PM   in response to: Jim Sawyer in response to: Jim Sawyer
Jim Sawyer wrote:


My question now, is what is the proper code for getting rid
of the temporary connection and query after I'm through with
them?

The correct answer is the same as for any other object in Delphi free
the object:

   Query.Free;
   TempConnection.Free;


On the other creating and freeing a temporary connection all the time
can slow down your application.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02