ChrisChuah 0 Posted December 7, 2022 Hi I am having a problem with this function. When issued a ClientDataset.open, the Before Open event is triggered but before the After event is triggered, it returned an Access violation ==== Access Violation Log ===== 22-12-7 14:46:48-10.100.252.26> LoadTableData2 SQL: SELECT ROW_ID,CREATED_AT,CREATED_BY,FIDSID,AODBID,EVENT,FLIGHT,DOMINT,SDT,TABLENAME,TABLENUMBER,XMLFILE FROM DYNAFLTS WHERE (CREATED_AT>=1670342400 and CREATED_AT<1670428800) <22-12-7 14:46:48-10.100.252.26> cdsDYNAFLTS Before Open <22-12-7 14:46:48-10.100.252.26> Error in LoadFilterTable: Access violation at address 00F5CC2B in module 'FidsEventViewer.exe'. Read of address 00000000 <22-12-7 14:46:48-10.100.252.26> App Exception: cdsDYNAFLTS: Cannot perform this operation on a closed dataset === ========= ==== Normal log on other machine ==== <7/12/2022 2:53:56 pm-192.168.0.124> LoadTableData2 SQL: SELECT ROW_ID,CREATED_AT,CREATED_BY,FIDSID,AODBID,SDT,FLIGHT,DOMINT,TABLENAME,EVENT,XMLFILE FROM DYNAFLTS WHERE (CREATED_AT>=1670342400 and CREATED_AT<1670428800) <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS Before Open <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS Start AfterOpen <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS Start read INI <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS End read INI <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS Assign Field to process <7/12/2022 2:53:56 pm-192.168.0.124> cdsDYNAFLTS End AfterOpen ============= In my code, the SQL is added to TQuery The Client dataset is link to the Provider. The provider is linked to TQuery. This application is run on another machine without this error but always gives an access violation on this machine. Is there a "cache" file that ClientDataset would read after the BeforeOpen event? Please advise regards chris Share this post Link to post
programmerdelphi2k 237 Posted December 7, 2022 3 hours ago, ChrisChuah said: App Exception: cdsDYNAFLTS: Cannot perform this operation on a closed dataset my tip: verify all points where your "query/clientdataset" is used! try verify if exists any try to access/changes state (open/close/edit/etc...)! it's not easy think if none code is showed Share this post Link to post
ChrisChuah 0 Posted December 8, 2022 hi attached is the code whereby it generated the error. The funny thing is that this app can run on other machines without error but only that particular machine. procedure TDataModule1.loadFilterTable; var l_str : string; l_ini : TIniFileEx; l_fieldList : string; begin if (trim(FFilterDay) = '') and (Trim(FFilterOthers) = '') then l_str := '' else if (Trim(FFilterDay) = '') and (Trim(FFilterOthers) <> '') then l_str := Trim(FFilterOthers) else if (Trim(FFilterDay) <> '') and (Trim(FFilterOthers) = '') then l_str := Trim(FFilterDay) else l_str := Trim(FFilterDay) + ' and ' + Trim(FFilterOthers); cdsDYNAFLTS.Close; qyDYNAFLTS.Close; if DataModule1.getLoginSuccess then begin try cdsDYNAFLTS.IndexName := ''; cdsDYNAFLTS.Filter := ''; cdsDYNAFLTS.Filtered := false; qyDYNAFLTS.SQL.Clear; l_Ini := TIniFileEx.create(ChangeFileExt(Application.ExeName, '.ini')); l_fieldList := l_ini.ReadString(DYNAFLTS_TABLE, INI_SECT_FIELDS, ''); // cc : if the field list is still empty, then make it a * if Trim(l_fieldList) = '' then l_fieldList := '*'; l_ini.Free; qyDYNAFLTS.SQL.Add('SELECT ' + l_fieldList + ' FROM ' + DYNAFLTS_TABLE ); if l_str <> '' then qyDYNAFLTS.SQL.Add(' WHERE ' + l_str); DoLog('LoadTableData2 SQL: ' + qyDYNAFLTS.SQL.Text); cdsDYNAFLTS.ProviderName := ''; cdsDYNAFLTS.ProviderName := 'dspDYNAFLTS'; cdsDYNAFLTS.Active := true; <== when open is called, the BeforeOpen will be logged. However the afterOpen is not called except on e:Exception do begin if not CheckDBConnectionError(e.message) then DoLog('Error in LoadFilterTable: ' + e.message); <== this will log down the access violation as shown int he log end; end; end; end; Share this post Link to post
programmerdelphi2k 237 Posted December 8, 2022 when using "TClientDataset" you can needs a "Midas" dll, if you dont compile with MidasLib in your project! program Project1; uses MidasLib, // <--- adding this, you'll dont needs DLL to MIDAS on target PC Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. Share this post Link to post