Everything posted by bazzer747
In my application I have a Data Module which has 2 FD Connections (one for Test site one for Live site) and over 20 FDQueries for all the tables and views (I connect to MS SQL Servers). My application fails quite regularly with error saying cannot access a closed dataset, and I think it is because at some stage I've used ExecSQL to insert or update a record and this appears to change the query in the FDQ. Which means I'm having to re-specify the sql query in code several times throughout the application. It seems to me that this isn't very good coding/design. I can't use the FDCExecSQL command as I'm flipping between the Test and Live connections, again I feel this isn't the right way to do this. If anybody can suggest a better way to manage my connectivity to avoid having to re-specify queries I would be very grateful.
Hi, Many thanks for all suggestions., I done a lot more thinking of my problems and come up with the following code: procedure ConnectLiveTest( fdc: String ); var i: Integer; begin for i := 0 to dm.ComponentCount -1 do if dm.Components[ i ] is TFDQuery then begin if fdc = 'Live' then TFDQuery( dm.Components[ i ]).Connection:= dm.fdcLive1 else TFDQuery( dm.Components[ i ]).Connection:= dm.fdcTest1; TFDQuery( dm.Components[ i ]).Active := True; end; end; This allows me to quickly switch between Test and Live MSSQL Server databases. And (whilst I'm still testing) appears to work OK.
FDSQL - sorry, shorthand! Meant FDConnection1.ExecSQL (see http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Executing_Commands_(FireDAC)). Thanks for tips here, I'll certainly look into both (Good job Chrome can translate pages :-)).