sql server - View output of 'print' statements using ADOConnection in Delphi -


some of ms sql stored procedures produce messages using 'print' command. in delphi 2007 application, connects ms sql using tadoconnection, how can view output of 'print' commands?

key requirements: 1) can't run query more once; might updating things. 2) need see 'print' results if datasets returned.

that interesting one...
the oninfomessage event adoconnection works devil in details!

main points:
use cursorlocation = cluseserver instead of default cluseclient.
use open , not execproc adostoredproc.
use nextrecordset current 1 following, sure check have 1 open.
use set nocount = on in stored procedure.

sql side: stored procedure

set ansi_nulls on go set quoted_identifier on go if  exists (select * sys.objects object_id = object_id(n'[dbo].[fg_test]') , type in (n'p', n'pc'))   drop procedure [dbo].[fg_test] go -- ============================================= -- author:      françois -- description: test multi ado info -- ============================================= create procedure fg_test begin     -- set nocount on absolutely needed     set nocount on;      print '*** start ***'      select 'one' set1field1      print '*** done once ***'      select 'two' set2field2      print '*** done again ***'      select 'three' set3field3      print '***finish ***' end go 

delphi side:
create new vcl forms application.
put memo , button in form.

copy following text, change catalog , data source , paste onto form

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 = <>   left = 24   top = 264 end 

in oninfomessage of adoconnection put

memo1.lines.add(error.description); 

for buttonclick, paste 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)   begin     // whatever current recordset     while not adostoredproc1.eof     begin       memo1.lines.add(adostoredproc1.fields[0].fieldname + ': ' + adostoredproc1.fields[0].value);       adostoredproc1.next;     end;     // switch subsequent recordset if     arecordset := adostoredproc1.nextrecordset(i);     if assigned(arecordset) , ((arecordset.state , adstateopen) <> 0)       adostoredproc1.recordset := arecordset     else       break;   end;    adostoredproc1.close; end; 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -