ZEOS 7.1 with Delphi7 and Lazarus 1.3
Why ZConnection1.ComponentCount does not work? always zero results .
I'm trying to have the same result as the old BDE Database1.DataSetCount, so I see what consigar TQuerys station open .
thank
Adilson Pazzini .
ZConnection1.ComponentCount
- EgonHugeist
- Zeos Project Manager
- Posts: 1936
- Joined: 31.03.2011, 22:38
Re: ZConnection1.ComponentCount
Hi.
The ComponentCount of TZConnection should always be null if this component doesnt own other components.
You could force it by creating the DataSet-components on the fly like
You could also ask the TForm for ComponentCount and compare the TZDataSet.ZConnection property.
But we could also add a public readonly property "DatasetCount" if you would prefere this way..
The ComponentCount of TZConnection should always be null if this component doesnt own other components.
You could force it by creating the DataSet-components on the fly like
Code: Select all
ZQuery := TZQuery.Create(ZConnection1);
But we could also add a public readonly property "DatasetCount" if you would prefere this way..
Best regards, Michael
You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/
You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/
-
- Fresh Boarder
- Posts: 8
- Joined: 16.10.2013, 16:37
Re: ZConnection1.ComponentCount
Thanks for the feedback,
Actually what I'm trying to develop a mechanism for reconnection is the Firebird database, because sometimes the connection drops, there have to close the application and abrila again, wanted to try to develop a mechanism where I catch all the datasets conseguise open before drop and rebuild them if detected the fall ...
Today I am trying to work with the Exception
Exception .. Class: EZSQLException
Message of the Exception: SQL Error: Unable to complete network request to host "211.2.111.1". Error writing data to the connection .. Error Code: -902. Unsuccessful execution Caused by the system error que precludes successful execution of subsequent statements
it was up there trying to catch the datasets open to recrialos qndo detected the drop in connection.
Actually what I'm trying to develop a mechanism for reconnection is the Firebird database, because sometimes the connection drops, there have to close the application and abrila again, wanted to try to develop a mechanism where I catch all the datasets conseguise open before drop and rebuild them if detected the fall ...
Today I am trying to work with the Exception
Exception .. Class: EZSQLException
Message of the Exception: SQL Error: Unable to complete network request to host "211.2.111.1". Error writing data to the connection .. Error Code: -902. Unsuccessful execution Caused by the system error que precludes successful execution of subsequent statements
it was up there trying to catch the datasets open to recrialos qndo detected the drop in connection.
You do not have the required permissions to view the files attached to this post.
-
- Fresh Boarder
- Posts: 8
- Joined: 16.10.2013, 16:37
Re: ZConnection1.ComponentCount
procedure TSISHandleException.AppException(Sender:TObject; E:Exception);
var
Log: TextFile;
ErrCode,i,x,y :integer;
AConected :boolean;
ASource: TComponent;
Formulario :TForm;
IdentificadorQuery:tstringlist ;
IdentificadorForm:tstringlist ;
begin
{$I-}
try
IdentificadorQuery := TStringList.Create;
identificadorQuery.Clear ;
IdentificadorForm := TStringList.Create;
identificadorForm.Clear ;
AssignFile(Log, FLogFile);
if FileExists(FLogFile) then
Append(Log)
else
Rewrite(Log);
try
WriteLn(Log, 'Exception ocorrida em '+
FormatDateTime('dd" de "mmmm" de "yyyy" às "hh:nn:ss', Now));
WriteLn(Log,'-------------------------------------------------------------------');
if TComponent(sender) is TForm then
begin
WriteLn(Log,'Form.................: '+TForm(sender).Name);
WriteLn(Log,'Caption do Form......: '+TForm(sender).Caption);
end else
begin
WriteLn(Log,'Form.................: '+TForm(TComponent(sender).Owner).Name);
WriteLn(Log,'Caption do Form......: '+TForm(TComponent(sender).Owner).Caption);
end;
WriteLn(Log,'-------------------------------------------------------------------');
WriteLn(Log,'Usuario..............: '+USUARIO);
WriteLn(Log,'Classe da Exception..: '+E.ClassName);
WriteLn(Log,'Mensagem da Exception: '+E.Message);
// if E is EDBEngineError then
// WriteLn(Log,'Erro : '+inttostr((E as EDatabaseError).Errors[0].ErrorCode));
{
if (E is EDatabaseError) then
begin
case EZSQLException(E).ErrorCode of
1451:
Application.MessageBox(PChar('Não é possível excluir este registro.'),
'Atenção !!!', MB_ICONEXCLAMATION);
else
ShowMessage(IntToStr( EZSQLException(E).ErrorCode));
end;
end;
}
{ if E is EDatabaseError then
WriteLn(Log,'Erro : '+inttostr((E as EZSQLException).Errors[0].ErrorCode));}
if E is Exception then
if (E.ClassName = 'EZSQLException') and (AnsiPos('Unable to complete network request to host',E.message) > 0) then
WriteLn(Log,'Erro : Queda de Conexao Banco de Dados');
WriteLn(Log,'');
MessageDlg(E.Message,MtError,[mbOK],0);
finally
CloseFile(Log);
end;
//===== TRATAMENTO
if TComponent(sender) is TForm then //--- Get ... MENU01.Active
Formulario := TForm(sender)
else
Formulario := TForm(TComponent(sender).Owner) ;
AConected := false;
if E is Exception then
begin
if (E.ClassName = 'EZSQLException') and (AnsiPos('Unable to complete network request to host',E.message) > 0) then
begin
while not AConected do
begin
try
//===> reconectando ............
for x := 0 to DM.DATABASE.ComponentCount-1 do // .DATABASE.DataSetCount-1 do
begin
//ShowMessage(dm.DATABASE.DataSets[x].Owner.Name+'.'+dm.DATABASE.DataSets[x].Name);
identificadorQuery.Add(dm.DATABASE.Components[x].Name);
identificadorForm.Add(dm.DATABASE.Components[x].Owner.Name);
end;
DM.DATABASE.Connected := false;
AConected := true;
DM.DATABASE.Connect;
for i := 0 to Application.ComponentCount-1 do
if (Application.Components is TForm) then
begin
//ShowMessage(TForm(Application.Components).Name);
for y := 0 to TForm(Application.Components).ComponentCount-1 do
if TForm(Application.Components).Components[y] is TZQuery then //ShowMessage(TForm(Application.Components).Components[y].Name);
for x := 0 to identificadorQuery.Count-1 do
if (TForm(Application.Components).Components[y].Name = identificadorQuery[x]) and (TForm(Application.Components).Components[y].Owner.Name = identificadorForm[x]) then //ShowMessage(identificadorForm[x]+'.'+identificadorQuery[x]);
begin
//ShowMessage(TForm(Application.Components).Components[y].Owner.Name+'.'+TForm(Application.Components).Components[y].Name);
TZQuery(TForm(Application.Components).Components[y]).Open;
end;
end//se existe formulario ...
else
if (Application.Components[i] is TDataModule) then
begin
//ShowMessage(TDataModule(Application.Components[i]).Name);
for y := 0 to TDataModule(Application.Components[i]).ComponentCount-1 do
if TDataModule(Application.Components[i]).Components[y] is TZQuery then //ShowMessage(TDataModule(Application.Components[i]).Components[y].Name);
for x := 0 to identificadorQuery.Count-1 do
if (TDataModule(Application.Components[i]).Components[y].Name = identificadorQuery[x]) and (TDataModule(Application.Components[i]).Components[y].Owner.Name = identificadorForm[x]) then //ShowMessage(identificadorForm[x]+'.'+identificadorQuery[x]);
begin
//ShowMessage(TDataModule(Application.Components[i]).Components[y].Owner.Name+'.'+TDataModule(Application.Components[i]).Components[y].Name);
TZQuery(TDataModule(Application.Components[i]).Components[y]).Open;
end;
end;//se existe formulario ...
except
On E: Exception do
begin
// ErrCode := (E as EDBEngineError).Errors[0].ErrorCode;
if MessageDlg('Formulário :'+Formulario.name+' Mensagem: '+E.Message+#13+#10+
'Deseja tentar se Re-conectar novamente ao Banco de Dados ?', mtConfirmation, [mbYes,MbNo], 0) = mrNo then
begin
Break;
end;
end;
end;
end;// while ;;;;
if AConected = false then
Application.Terminate;
end;
end;
finally
identificadorquery.Free ;
identificadorform.Free;
end;
{$I+}
end;
var
Log: TextFile;
ErrCode,i,x,y :integer;
AConected :boolean;
ASource: TComponent;
Formulario :TForm;
IdentificadorQuery:tstringlist ;
IdentificadorForm:tstringlist ;
begin
{$I-}
try
IdentificadorQuery := TStringList.Create;
identificadorQuery.Clear ;
IdentificadorForm := TStringList.Create;
identificadorForm.Clear ;
AssignFile(Log, FLogFile);
if FileExists(FLogFile) then
Append(Log)
else
Rewrite(Log);
try
WriteLn(Log, 'Exception ocorrida em '+
FormatDateTime('dd" de "mmmm" de "yyyy" às "hh:nn:ss', Now));
WriteLn(Log,'-------------------------------------------------------------------');
if TComponent(sender) is TForm then
begin
WriteLn(Log,'Form.................: '+TForm(sender).Name);
WriteLn(Log,'Caption do Form......: '+TForm(sender).Caption);
end else
begin
WriteLn(Log,'Form.................: '+TForm(TComponent(sender).Owner).Name);
WriteLn(Log,'Caption do Form......: '+TForm(TComponent(sender).Owner).Caption);
end;
WriteLn(Log,'-------------------------------------------------------------------');
WriteLn(Log,'Usuario..............: '+USUARIO);
WriteLn(Log,'Classe da Exception..: '+E.ClassName);
WriteLn(Log,'Mensagem da Exception: '+E.Message);
// if E is EDBEngineError then
// WriteLn(Log,'Erro : '+inttostr((E as EDatabaseError).Errors[0].ErrorCode));
{
if (E is EDatabaseError) then
begin
case EZSQLException(E).ErrorCode of
1451:
Application.MessageBox(PChar('Não é possível excluir este registro.'),
'Atenção !!!', MB_ICONEXCLAMATION);
else
ShowMessage(IntToStr( EZSQLException(E).ErrorCode));
end;
end;
}
{ if E is EDatabaseError then
WriteLn(Log,'Erro : '+inttostr((E as EZSQLException).Errors[0].ErrorCode));}
if E is Exception then
if (E.ClassName = 'EZSQLException') and (AnsiPos('Unable to complete network request to host',E.message) > 0) then
WriteLn(Log,'Erro : Queda de Conexao Banco de Dados');
WriteLn(Log,'');
MessageDlg(E.Message,MtError,[mbOK],0);
finally
CloseFile(Log);
end;
//===== TRATAMENTO
if TComponent(sender) is TForm then //--- Get ... MENU01.Active
Formulario := TForm(sender)
else
Formulario := TForm(TComponent(sender).Owner) ;
AConected := false;
if E is Exception then
begin
if (E.ClassName = 'EZSQLException') and (AnsiPos('Unable to complete network request to host',E.message) > 0) then
begin
while not AConected do
begin
try
//===> reconectando ............
for x := 0 to DM.DATABASE.ComponentCount-1 do // .DATABASE.DataSetCount-1 do
begin
//ShowMessage(dm.DATABASE.DataSets[x].Owner.Name+'.'+dm.DATABASE.DataSets[x].Name);
identificadorQuery.Add(dm.DATABASE.Components[x].Name);
identificadorForm.Add(dm.DATABASE.Components[x].Owner.Name);
end;
DM.DATABASE.Connected := false;
AConected := true;
DM.DATABASE.Connect;
for i := 0 to Application.ComponentCount-1 do
if (Application.Components is TForm) then
begin
//ShowMessage(TForm(Application.Components).Name);
for y := 0 to TForm(Application.Components).ComponentCount-1 do
if TForm(Application.Components).Components[y] is TZQuery then //ShowMessage(TForm(Application.Components).Components[y].Name);
for x := 0 to identificadorQuery.Count-1 do
if (TForm(Application.Components).Components[y].Name = identificadorQuery[x]) and (TForm(Application.Components).Components[y].Owner.Name = identificadorForm[x]) then //ShowMessage(identificadorForm[x]+'.'+identificadorQuery[x]);
begin
//ShowMessage(TForm(Application.Components).Components[y].Owner.Name+'.'+TForm(Application.Components).Components[y].Name);
TZQuery(TForm(Application.Components).Components[y]).Open;
end;
end//se existe formulario ...
else
if (Application.Components[i] is TDataModule) then
begin
//ShowMessage(TDataModule(Application.Components[i]).Name);
for y := 0 to TDataModule(Application.Components[i]).ComponentCount-1 do
if TDataModule(Application.Components[i]).Components[y] is TZQuery then //ShowMessage(TDataModule(Application.Components[i]).Components[y].Name);
for x := 0 to identificadorQuery.Count-1 do
if (TDataModule(Application.Components[i]).Components[y].Name = identificadorQuery[x]) and (TDataModule(Application.Components[i]).Components[y].Owner.Name = identificadorForm[x]) then //ShowMessage(identificadorForm[x]+'.'+identificadorQuery[x]);
begin
//ShowMessage(TDataModule(Application.Components[i]).Components[y].Owner.Name+'.'+TDataModule(Application.Components[i]).Components[y].Name);
TZQuery(TDataModule(Application.Components[i]).Components[y]).Open;
end;
end;//se existe formulario ...
except
On E: Exception do
begin
// ErrCode := (E as EDBEngineError).Errors[0].ErrorCode;
if MessageDlg('Formulário :'+Formulario.name+' Mensagem: '+E.Message+#13+#10+
'Deseja tentar se Re-conectar novamente ao Banco de Dados ?', mtConfirmation, [mbYes,MbNo], 0) = mrNo then
begin
Break;
end;
end;
end;
end;// while ;;;;
if AConected = false then
Application.Terminate;
end;
end;
finally
identificadorquery.Free ;
identificadorform.Free;
end;
{$I+}
end;