Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That was an interesting one...<br> <strong>The OnInfoMessage event from the ADOConnection works but the Devil is in the details!</strong></p> <p><strong>Main points:</strong><br> use CursorLocation = clUseServer instead of the default clUseClient.<br> use Open and not ExecProc with your ADOStoredProc.<br> use NextRecordset from the current one to get the following, but be sure to check you have one open.<br> use SET NOCOUNT = ON in your stored procedure. </p> <p><strong>SQL side:</strong> your stored procedure</p> <pre><code>SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FG_TEST]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[FG_TEST] GO -- ============================================= -- Author: François -- Description: test multi ADO with info -- ============================================= CREATE PROCEDURE FG_TEST AS BEGIN -- SET NOCOUNT ON absolutely NEEDED SET NOCOUNT ON; PRINT '*** start ***' SELECT 'one' as Set1Field1 PRINT '*** done once ***' SELECT 'two' as Set2Field2 PRINT '*** done again ***' SELECT 'three' as Set3Field3 PRINT '***finish ***' END GO </code></pre> <p><strong>Delphi side:</strong><br> Create a new VCL Forms Application.<br> Put a Memo and a Button in your Form. </p> <p>Copy the following text, change the Catalog and Data Source and Paste it onto your Form </p> <pre><code>object ADOConnection1: TADOConnection ConnectionString = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' + 'fo=False;Initial Catalog=xxxYOURxxxDBxxx;Data Source=xxxYOURxxxSERVERxxx' CursorLocation = clUseServer LoginPrompt = False Provider = 'SQLOLEDB.1' OnInfoMessage = ADOConnection1InfoMessage Left = 24 Top = 216 end object ADOStoredProc1: TADOStoredProc Connection = ADOConnection1 CursorLocation = clUseServer ProcedureName = 'FG_TEST;1' Parameters = &lt;&gt; Left = 24 Top = 264 end </code></pre> <p>In the OnInfoMessage of the ADOConnection put</p> <pre><code>Memo1.Lines.Add(Error.Description); </code></pre> <p>For the ButtonClick, paste this code</p> <pre><code>procedure TForm1.Button1Click(Sender: TObject); const adStateOpen = $00000001; // or defined in ADOInt var I: Integer; ARecordSet: _Recordset; begin Memo1.Lines.Add('=========================='); ADOStoredProc1.Open; // not ExecProc !!!!! ARecordSet := ADOStoredProc1.Recordset; while Assigned(ARecordSet) do begin // do whatever with current RecordSet while not ADOStoredProc1.Eof do begin Memo1.Lines.Add(ADOStoredProc1.Fields[0].FieldName + ': ' + ADOStoredProc1.Fields[0].Value); ADOStoredProc1.Next; end; // switch to subsequent RecordSet if any ARecordSet := ADOStoredProc1.NextRecordset(I); if Assigned(ARecordSet) and ((ARecordSet.State and adStateOpen) &lt;&gt; 0) then ADOStoredProc1.Recordset := ARecordSet else Break; end; ADOStoredProc1.Close; end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload