Console FireDAC Example wanted
Doing FireDAC againt MSSQL or PostgreSQL visually is easy, but when I try to do it in code only – I get weird errors and there must be something essential that I miss.
Does anyone have a code only example of how to set up a FireDAC connection?
What’r the error messages?
I had problems if I did not add tons of stuff into the Uses Clause, drivers and so… They just need to be some where, and if in Console most likely not some is missing…
I set these params on the BeforeOpen, see if it helps :
myDatabase.Params.Values[‘Password’] := ‘***’;
myDatabase.Params.Values[‘User_Name’] := ‘postgres’;
myDatabase.Params.Values[‘Database’] := ‘mydatabasename’;
myDatabase.Params.Values[‘Port’] := ‘5432’;
myDatabase.Params.Values[‘Server’] := ‘127.0.0.1’;
Besides, I have no problems with FD and PG.
You could use a TDataModule to hold the FireDAC components and then you create an instance of this TDataModule in your code.
function TFDAdaptedDataSet.GetOptionsIntf: IFDStanOptions;
begin
Result := Command.OptionsIntf;
AV because Command is nil
Stack:
FireDAC.Comp.Client.TFDAdaptedDataSet.GetOptionsIntf
FireDAC.Comp.DataSet.TFDDataSet.GetResourceOptions
FireDAC.Comp.DataSet.TFDDataSet.StartWait
FireDAC.Comp.DataSet.TFDDataSet.OpenCursor(False)
Data.DB.TDataSet.SetActive(???)
Magno Lima
FConnection.Params.Add(‘DriverId=MSSQL’);
FConnection.Params.Add(‘Server=’+Trim(FHost));
FConnection.Params.Add(‘Database=’+Trim(FDatabaseName));
FConnection.Params.Add(‘OSAuthent=No’);
FConnection.Params.Add(‘User_Name=’+Trim(FUserName));
FConnection.Params.Add(‘Password=’+Trim(FPassword));
Panagiotis Drivilas – Surely it must be possible to use this without design time components!
For example MSSQL:
1. Create a TFDPhysMSSQLDriverLink instance
2. Create a TFDConnection and set the params
3. Create a TFDQuery and set the connection
The driver link has to be created only once for the application, while the connection has to be separate for each connection(obviously) and for each thread. Make sure to say “uses uFDGUIxConsoleWait” somewhere.
Uwe Raabe
1. Check – Single instance
2. Check – One instance per target server
3. Check
uFDGUIxConsoleWait is named FireDAC.ConsoleUI.Wait in XE6 and XE7. Does it matter if it is included in a GUI app as well?
Still same problem.
I get a successful connect. It seems I am missing something crucial regarding TFDQuery and TFDCommand.
Please set a break point on
unit FireDAC.Comp.Client;
function TFDAdaptedDataSet.GetCommand: TFDCustomCommand; //BP here
begin
if Adapter nil then
Result := Adapter.SelectCommand // you lack of SelectCommand?
else
Result := nil;
end;
if AV cause by Command is nil.
Sam Shaw Adapter is assigned.
The actual code is a rewrite of ADO code, and I am starting to suspect that I am doing some silly ADOism where I should be doing things differently and the FireDAC way.
Lars Fosdal , I love using ADO and use many. For me, firedac is similar to ADO model, but still some are different. It’s worthy to spend a couple of minutes to read the following documentation if you didn’t yet.
http://docs.embarcadero.com/products/rad_studio/firedac/frames.html
🙂
Lars Fosdal Unless using Params.Clear, should not use Params.Add() that way, even when creating the database connection programmatically.
Magno Lima – Well, it works. The DB connects. It’s when I try to do a query that I’ve screwed up.
Sam Shaw – The FireDAC documentation you linked is outdated.
Lars Fosdal so where is the new one? 🙁
Sam Shaw – Well, it’s in the XE7 docs – but not quite as tidy.
Lars Fosdal yes it works, but as it is a string list will add new line and by default using the last one… Maybe someone told but dont forget using TWaitCursor. When creating FD connection for postgres in runtime I dont mess with any other parameter but that I told first. I am using XE5.
I changed the code, Magno Lima – just to be on the safe side 🙂