FireDAC WTF of the day ;)
FireDAC WTF of the day ;)
Conn := TFDConnection.Create(nil);
Conn.DriverName := FireDriverLink.BaseDriverId;
// The above lines were actually in a function in the worker pool
for tgt in targetlist
do begin
Conn.Params.Clear;
Conn.Params.Values['Server'] := tgt.Host;
Conn.Params.Values['Database'] := tgt.DatabaseName;
Conn.Params.Values['OSAuthent'] := 'No';
Conn.Params.Values['User_Name'] := tgt.UserName;
Conn.Params.Values['Password'] := tgt.Password;
Conn.Connect;
Exception: Driver name not set.
I added the above clear since I would be reusing the connection for multiple databases in a loop, and it took me a few rounds in the debugger before I figured out that the property mapped into the params list instead of a property field of it's own.
Lesson learned.
Conn := TFDConnection.Create(nil);
Conn.DriverName := FireDriverLink.BaseDriverId;
// The above lines were actually in a function in the worker pool
for tgt in targetlist
do begin
Conn.Params.Clear;
Conn.Params.Values['Server'] := tgt.Host;
Conn.Params.Values['Database'] := tgt.DatabaseName;
Conn.Params.Values['OSAuthent'] := 'No';
Conn.Params.Values['User_Name'] := tgt.UserName;
Conn.Params.Values['Password'] := tgt.Password;
Conn.Connect;
Exception: Driver name not set.
I added the above clear since I would be reusing the connection for multiple databases in a loop, and it took me a few rounds in the debugger before I figured out that the property mapped into the params list instead of a property field of it's own.
Lesson learned.
That's naughty, and worse if it's not documented.
ReplyDeleteI cannot grasp the point :-)
ReplyDeleteCan you please expose a more complete snippet?
From AnyDAC documentation:
ReplyDeletewith ADConnection1.Params do begin
Clear;
Add('DriverID=Ora');
Add('Database=ORA_920_APP');
Add('User_Name=ADDemo');
Add('Password=a');
end;
ADConnection1.Connected := True;
Fabio VITALE The issue is that the DriverName on the connection class actually sets a parameter, so when you call Params.Clear you remove the driver name as well.
ReplyDeleteFabio VITALE - The FireDAC documentation is largely oriented towards using the components by dropping them on a form, rather than setting things up in source code. It is possible that it is documented somewhere that the "DriverName" property is mapped into the Params list, but I failed to spot that piece of information.
ReplyDeleteThey definitely need more documentation on this. Anyone with a test and production environment which I assume is almost everyone needs to change these parameters at run time.
ReplyDeleteAsbjørn Heid and Lars Fosdal: Crystal clear! Thank you all:-)
ReplyDelete