i've got perl using DBI to connect to our MS SQL Server database.. everythings working fine so far.. but i can't figure out how to print out an error message when there's an error in a trigger on a MS SQL table.. here's the main part of the code:
if($dbh = DBI->connect($connectionInfo,$userid,$passwd)){ $sth = $dbh->prepare($query); if($sth->execute()){ @dsetcols=[]; $xi=0; @fieldnames = split(/,/, $fnames); foreach $fieldname (@fieldnames) { $ds{$dsetname}{$fieldname}=[]; push @dsetcols,""; $sth->bind_col($xi+1,\$dsetcols[$xi]); if ($fieldname eq "task_id") { } $xi++; } while($sth->fetch()) { $xi=0; foreach $fieldname (@fieldnames) { push @{$ds{$dsetname}{$fieldname}},safedecode($dsetcol +s[$xi]); $xi++; } } $sth->finish(); }else{ print "Query \""; print $query; print "\" failed.<br>"; print "Database error message: "; print $dbh->errstr; print "<p>"; # used in do_autorefresh, detail window won't automatica +lly close if query failed $badquery = 1; } $dbh->disconnect; }else{print "Could not connect to database.<br>";} } $x++; }
when there's an error in a query, like say its trying to update a field in the table and the type isn't correct, it'll print out my error message.. however, i have a trigger on a table, and in that trigger, if it found something, i.e. field1 != field2, then it will raise an error in SQL server, but it looks like DBI doesn't catch that error here's the code inside the trigger:
IF (@max_vendor != (SELECT vendor_id FROM Inserted)) BEGIN RAISERROR ('PO already exists with a different vendor',16,1) ROLLBACK TRAN END
any idea on why this isn't working? ive been doing some testing.. and DBI will report the SQL error given by the trigger if i'm doing an INSERT statement into a table and that table has a trigger on inserts and updates.. however if i do a UPDATe statement on that table, DBI would report the SQL error given by the trigger thanks!

In reply to perl w/ DBI connectiong to MSSQL, not reporting SQL server trigger errors by chauzer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.