Console FireDAC Example wanted
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?
#firedac
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?
#firedac
What'r the error messages?
ReplyDeleteI 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...
ReplyDeleteI set these params on the BeforeOpen, see if it helps :
ReplyDeletemyDatabase.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.
ReplyDeletefunction TFDAdaptedDataSet.GetOptionsIntf: IFDStanOptions;
ReplyDeletebegin
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
ReplyDeleteFConnection.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!
ReplyDeleteFor example MSSQL:
ReplyDelete1. 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
ReplyDelete1. 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.
ReplyDeletePlease set a break point on
ReplyDeleteunit 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.
ReplyDeleteThe 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.
ReplyDeletehttp://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.
ReplyDeleteMagno Lima - Well, it works. The DB connects. It's when I try to do a query that I've screwed up.
ReplyDeleteSam Shaw - The FireDAC documentation you linked is outdated.
ReplyDeleteLars Fosdal so where is the new one? :(
ReplyDeleteSam Shaw - Well, it's in the XE7 docs - but not quite as tidy.
ReplyDeleteLars 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.
ReplyDeleteI changed the code, Magno Lima - just to be on the safe side :)
ReplyDelete