title: Perl ADO thinks printed output in stored procedure is an error!
body: <p>First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built for MSWin32-x86-multi-thread).</p>
  
  <p>I've just emerged from a three hour long debugging session, trying to find the source of an error. I found there was simply no error, but for some reason ADO's connection object was getting the <code>Errors.Count</code> increased with each printed message in my stored procedure's output.</p>
  
  <p>Consider following Transact SQL code:</p>
  
  <pre><code>CREATE PROCEDURE dbo.My_Sample() AS
  BEGIN TRAN my_tran
  -- Does something useful
  if @@error &lt;&gt; 0 BEGIN
    ROLLBACK TRAN my_tran
    RAISERROR( 'SP My_Sample failed', 16, 1)
  END ELSE BEGIN
    COMMIT TRAN my_tran
    PRINT 'SP My_Sample succeeded'
  END
  </code></pre>
  
  <p>Now imagine a Perl sub more or less like:</p>
  
  <pre><code>sub execute_SQL {
    # $conn is an already opened ADO connection object
    # pointing to my SQL Server
    # $sql is the T-SQL statement to be executed
    my($conn, $sql) = @_;
    $conn-&gt;Execute($sql);
    my $error_collection = $conn-&gt;Errors();
    my $ecount = $error_collection-&gt;Count;
    if ($ecount == 0 ) { return 0; }
    print "\n" . $ecount . " errors found\n";
    print "Executed SQL Code:\n$sql\n\n";
    print "Errors while executing:\n";
    foreach my $error (in $error_collection){
      print "Error: [" . $error-&gt;{Number} . "] " . $error-&gt;{Description} . "\n";
    }
    return 1;
  }
  </code></pre>
  
  <p>Somewhere else, in the main Perl code, I'm calling the above sub as:</p>
  
  <pre><code>execute_SQL( $conn, 'EXEC dbo.My_Sample' );
  </code></pre>
  
  <p>In the end I got it that <em>every</em> PRINT statement causes a new pseudo-error to be appended to the ADO Errors collection. The quick fix I implemented was to change that PRINT in the SP into a SELECT, to bypass this.</p>
  
  <p>The questions I'd like to ask are:</p>
  
  <ul>
  <li>Is this behaviour normal?</li>
  <li>Is there a way to avoid/bypass it?</li>
  </ul>