-3

enter image description here I'm trying to capture the debugger notification text, Firedac connection

//FDScript1.SQLScripts.Add.SQL.LoadFromFile('C:\SGI\Rodar_Apos_Atualizar_3.txt');
//FDScript1.ValidateAll;
//FDScript1.ExecuteAll;
//MSScript1.SQL.LoadFromFile('C:\SGI\Rodar_Apos_Atualizar_3.txt');
//MSScript1.Execute;
try
  FDConnection1.Connected := True;
  FDScript1.SQLScripts.Add.SQL.LoadFromFile('C:\SGI\Rodar_Apos_Atualizar_3.txt');
  FDScript1.ExecuteAll;
  FDScript1.ValidateAll;
except
//EMSSQLNativeException
  on E: EMSSQLNativeException do
  begin
    //ShowMessage('Erro'+FDGUIxErrorDialog1.ErrorDialog.Caption);

    //Memo1.Clear;
    Memo1.Text := 'Erro de Sistema: '+#13#10+ E.Message;
  end;
end;

image

enter image description here

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • 1
    And, your *actual question* is ... what exactly? – Remy Lebeau May 16 '20 at 02:41
  • The error message seems to be talking about a syntax error near the keyword 'ON'. How can we readers possibly know what the syntax error when you haven't told us what script is executing when the error occurs? – MartynA May 16 '20 at 08:07
  • What he wants is preventing the debugger message box from appearing. – Olivier May 16 '20 at 09:26
  • Hi @Olivier. I'm afraid I don't follow your comment or perhaps I am missing your point. If the Sql Server is reporting a syntax error, we need to know the answer to "Syntax error in what, exactly?" don't we? – MartynA May 16 '20 at 09:35
  • @MartynA Sure but right now his problem is to properly catch the exception to show the error message the way he wants, log it or whatever. Look at his code, he tried to catch the `EMSSQLNativeException ` but the debugger still shows up. Not sure why. – Olivier May 16 '20 at 09:41
  • @Olivier as you act as a translator here :), please explain to user...: The debugger catches the error before user code. Just press `Continue` to let your own code catch it. Or note the checkbox in the left bottom corner. Check it and the debugger notification will not be shown anymore for this exception, and the code can catch it directly. – Tom Brunberg May 16 '20 at 10:27
  • Thank you all, but the error displayed is intentional, I want to catch the error and play in text in the Memo, and with E.Message it is not appearing in the memo – user10264787 May 16 '20 at 11:37
  • Oh... So it seems I didn't understand the question either, after all. Do you see at least `'Erro de Sistema: '` in the memo, or nothing at all? – Olivier May 16 '20 at 11:55
  • I don't see, because E. messaging is not returning anything – user10264787 May 16 '20 at 12:09
  • Strange. Did you try `E.Errors[0].Message`? – Olivier May 16 '20 at 13:57
  • I want to get the native error data bancco and play in FDGUIxScriptDialog memo as the image q put now in post – user10264787 May 16 '20 at 15:56

1 Answers1

2

It really would help if you would show us the scripts you are trying to execute, or at least the script which does not execute correctly. In any case, your code is wrong because the documentation states

It is good practice to call the ValidateAll method before the ExecuteAll method.

Note the 'before'. Your ValidateAll is after ExecuteAll, not before. Both are Boolean functions but you are not checking their results, which you should.

With some trivial experimenting I found that I can provoke a EMSSQLNativeException using SqlServer 2014 with the code below:

procedure TForm2.Button1Click(Sender: TObject);
const
  sScript = 'select m.*, d.* from master m join detail d on, m.masterid = d.masterid';
var
  FDScript : TFDSqlScript;
begin

  try
    FDConnection1.Connected := True;
    FDScript := FDScript1.SQLScripts.Add;
    FDScript.SQL.Text := sScript;
    //FDScript1.ExecuteAll;
    //FDScript1.ValidateAll;
    // FDScript1.ValidateAll then
      //FDScript1.ExecuteAll;

    FDQuery1.SQL.Text := sScript;
    FDQuery1.Open();
  except
  //EMSSQLNativeException
    on E: EMSSQLNativeException do
    begin
      //ShowMessage('Erro'+FDGUIxErrorDialog1.ErrorDialog.Caption);

      //Memo1.Clear;
      Memo1.Text := 'Erro de Sistema: '+#13#10+ E.Message;
    end;
  end;
end;

Note the blatantly wrong syntax in the Sql statement, namely the comma after the on.

When FDQuery1.Open is called, this exception is raised (and caught initially by the debugger)

---------------------------
Debugger Exception Notification
---------------------------
Project sqlerror.exe raised exception class EMSSQLNativeException with message '[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'd'.'.
---------------------------
Break   Continue   Help
---------------------------

When I click Continue, execution proceeds into your exception handler, exactly as @TomBrunberg described in a comment and the exception's message text is inserted into Memo1.

So I cannot reproduce the behaviour you describe based on the information in your question. It must be caused by something you are not telling us, possibly in code you have not included in your q or some property setting of the components you are using.

Hopefully, trying the code above, you will find the debugger behaving as I have described and this may give you some clue as to why you are getting the problem you've described. Note that it is very important that you try the code above in a new project, not your existing one. The only property setting you need to do before executing it is to set FDConnection1 so that it can connect to your server.

FWIW, if I uncomment-out the lines

    FDScript1.ValidateAll then
      FDScript1.ExecuteAll;

they execute without complaint, and I get the exact same behaviour as i've described without them.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Oh, great. then please feel free to accept this answer by clicking the 'tick' icon on its lefthand side. – MartynA May 17 '20 at 03:58