Board index » delphi » ADO and retrieving MS SQL messages / PRINT statement text

ADO and retrieving MS SQL messages / PRINT statement text

Does anyone know how to retrieve/trap messages after executing a SQL
statement.

I would like to be be able to use a similar approach to Microsoft Query
analyser's 'Message' window, which allows you to see PRINT messages, Syntax
errors etc.

 

Re:ADO and retrieving MS SQL messages / PRINT statement text


Just setup the "ConnectionEvents" in the TADOConnection object.

Ex:

    FOnBeginTransComplete: TBeginTransCompleteEvent;
    FOnConnectComplete: TConnectErrorEvent;
    FOnCommitTransComplete: TConnectErrorEvent;
    FOnRollbackTransComplete: TConnectErrorEvent;
    FOnDisconnect: TDisconnectEvent;
    FOnInfoMessage: TInfoMessageEvent;
    FOnWillConnect: TWillConnectEvent;
    FOnExecuteComplete: TExecuteCompleteEvent;
    FOnWillExecute: TWillExecuteEvent;

Dennis Passmore
Ultimate Software, Inc

Re:ADO and retrieving MS SQL messages / PRINT statement text


Quote
>Does anyone know how to retrieve/trap messages after executing a SQL
>statement.

Examine the TadoConnection.Errors collection after executing the SQL.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:ADO and retrieving MS SQL messages / PRINT statement text


Still cannot get any print statement text

I have tried the following code....
------------------------------------------------------------
   MemoMessages.lines.clear;
   ADOCMD.commandtext := MemoSQL.text;
   ADOCMD.execute;
   if ADOCON.errors.Count = 0 then
      MemoMessages.lines.add('No Errors')
   else
      for i := 0 to ADOCON.errors.Count-1 do
         with ADOCON.errors[i] do begin
            s := 'Error Number : '+IntToStr(Number) +#13#10
            + 'Source       : '+Source+#13#10
            + 'Description  : '+Description+#13#10
            + 'Help File    : '+HelpFile+#13#10
            + 'Help Context : '+IntToStr(HelpContext)+#13#10
            + 'SQL State    : '+SQLState+#13#10
            + 'NativeError  : '+IntToStr(NativeError);
            MemoMessages.lines.Add(s);
         end;
------------------------------------------------------------

I used this simple script...
------------------------------------------------------------
PRINT 'Hello...'
SELECT * FROM [Northwind].[dbo].[categories]
PRINT '...World'
------------------------------------------------------------

And got no error messages. Where has the PRINT output gone to?

I also tried looking at the ADOCON events  OnCommitTrans, OnInfoMessage,
OnWillExecute and OnExecute complete and nothing
showed me the output from the print statements.

When I tried using MS Query Analyser I got the following messages...
---------------------------
Hello

(8 row(s) affected)

World
--------------------------
And this is what I am trying to achieve.

"Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
news:19fart49qvq42e43io5tocdvmidvj9vskn@4ax.com...

Quote

> >Does anyone know how to retrieve/trap messages after executing a SQL
> >statement.

> Examine the TadoConnection.Errors collection after executing the SQL.

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:ADO and retrieving MS SQL messages / PRINT statement text


Hi TonyR,

Quote
> I have tried the following code....
> ------------------------------------------------------------
>    MemoMessages.lines.clear;

[...]

Quote
> I used this simple script...
> ------------------------------------------------------------
> PRINT 'Hello...'
> SELECT * FROM [Northwind].[dbo].[categories]
> PRINT '...World'
> ------------------------------------------------------------

I am not sure to understand the link between your code and you script (if there is one).

How do you use MemoMessages once you have filled it? Did you try using a MessageBox to
show if the right information is in MemoMessages.Lines after you have run your code?

Thrse

Re:ADO and retrieving MS SQL messages / PRINT statement text


Hi TonyR,

Quote
> How do you use MemoMessages once you have filled it?

Sorry, this was a stupid question - confused TMemo and TStrings.

Thrse

Re:ADO and retrieving MS SQL messages / PRINT statement text


See:

http://community.borland.com/article/0,1410,20245,00.html

Article title: MS SQL Server 7 Stored Procedure PRINT Statements with ADO

quote:
...
Another fact worth pointing out is that Print statement messages are only
placed in the Errors collection if the ADO command is executed with the
eoExecuteNoRecords Option set to True.
...

Herman Fr?berg

Quote
"TonyR" <dome...@hotmail.com> wrote in message news:3bb838dc$1_1@dnews...
> Still cannot get any print statement text

> I have tried the following code....
> ------------------------------------------------------------
>    MemoMessages.lines.clear;
>    ADOCMD.commandtext := MemoSQL.text;
>    ADOCMD.execute;
>    if ADOCON.errors.Count = 0 then
>       MemoMessages.lines.add('No Errors')
>    else
>       for i := 0 to ADOCON.errors.Count-1 do
>          with ADOCON.errors[i] do begin
>             s := 'Error Number : '+IntToStr(Number) +#13#10
>             + 'Source       : '+Source+#13#10
>             + 'Description  : '+Description+#13#10
>             + 'Help File    : '+HelpFile+#13#10
>             + 'Help Context : '+IntToStr(HelpContext)+#13#10
>             + 'SQL State    : '+SQLState+#13#10
>             + 'NativeError  : '+IntToStr(NativeError);
>             MemoMessages.lines.Add(s);
>          end;
> ------------------------------------------------------------

> I used this simple script...
> ------------------------------------------------------------
> PRINT 'Hello...'
> SELECT * FROM [Northwind].[dbo].[categories]
> PRINT '...World'
> ------------------------------------------------------------

> And got no error messages. Where has the PRINT output gone to?

> I also tried looking at the ADOCON events  OnCommitTrans, OnInfoMessage,
> OnWillExecute and OnExecute complete and nothing
> showed me the output from the print statements.

> When I tried using MS Query Analyser I got the following messages...
> ---------------------------
> Hello

> (8 row(s) affected)

> World
> --------------------------
> And this is what I am trying to achieve.

> "Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
> news:19fart49qvq42e43io5tocdvmidvj9vskn@4ax.com...

> > >Does anyone know how to retrieve/trap messages after executing a SQL
> > >statement.

> > Examine the TadoConnection.Errors collection after executing the SQL.

> > --
> > Brian Bushay (TeamB)
> > Bbus...@NMPLS.com

Re:ADO and retrieving MS SQL messages / PRINT statement text


Hi TonyR,

Quote
> How do you use MemoMessages once you have filled it?

Sorry, this was a stupid question - confused TMemo and TStrings.

Thrse

Re:ADO and retrieving MS SQL messages / PRINT statement text


Herman,

Thankyou for your help, the article is just what I was looking for.

TonyR

Other Threads