ZSQLMonitor error.

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
delphiec
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 19.12.2016, 02:36

ZSQLMonitor error.

Post by delphiec »

When I actovate ZSQLMonitor my application is crash.

Problem was described here: https://sourceforge.net/p/zeoslib/tickets/182/

How can I get SQL errors without using ZSQLMonitor?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZSQLMonitor error.

Post by marsupilami »

Hello delphiec,

it seems that TZSQLMonitor is not thread safe. But it is meant to be used as a debugging component for fining communication problems between your application and the database anyway.
SQL Errors usually should be raised as Exceptions that you can catch in your code and then log with a logging mechanism of your choice?

With best regards,

Jan
delphiec
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 19.12.2016, 02:36

Re: ZSQLMonitor error.

Post by delphiec »

No, it is created in each stream separately.
Maybe I Do not know about some of the nuance. Or I need to enable some option?
Can you show example?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZSQLMonitor error.

Post by marsupilami »

Hello delphiec,

TZSQLMonitor is not a good component for doing what you want. You might want something like this:

Code: Select all

unit test

interface

procedure DoSomeThing;
procedure LogError(Message: String);

var
  CriticalSection: TCriticalSection;

implementation

procedure DoSomeThing;
begin
  // do soemthing that is not dbrelated here...
  try
    // do something db related here
  except
    on E: Exception do begin
      LogError(E.Message);
    end;
  end;
end;

procedure LogError(Message: String);
var
  LogFile: TextFile;
begin
  try
    CriticalSection.Enter;
    AssignFile(TextFile, 'C:\test.log');
    Append(TextFile);
    Writeln(TextFile, Now, ' ', Message);
    CloseFile(LogFile);
  finally
    CriticalSection.Leave;
  end;
end;

initialization
  CriticalSection := TCriticalSection.Create;

finalization
  FreeAndNil(CriticalSection);

end.
Beware: This code was written without testing or even reading the delphi help files. But it should show you what I mean.
delphiec
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 19.12.2016, 02:36

Re: ZSQLMonitor error.

Post by delphiec »

I wanna get sql error, but code above don't let me.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZSQLMonitor error.

Post by marsupilami »

Hello delphiec,

what exactly do you mean by sql error? What is your environment (Database, Zeoslib driver, Delphi / Lazarus version)? What is captured by TZSQLMonitor that doesn't get into the exception. Can you maybe post a log and higlight in there what information you want to have?

With best regards,

Jan
delphiec
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 19.12.2016, 02:36

Re: ZSQLMonitor error.

Post by delphiec »

Zsqlmonitor code in "try except end" is experimental code, I need to get sql-server errors.
But if I set ZSQLMonitor1.Active:=true;, I get "double free or corruption error". Something wrong into ZSQLMonitor module.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZSQLMonitor error.

Post by marsupilami »

You don't need TZSQLMonitor to get SQL Server Errors. SQL Server Errors will be raised as Exceptions.
Post Reply