Wrong value returned for RecordsAffected

From: Paul Ballarin (anonymous_at_discussions.microsoft.com)
Date: 02/23/04


Date: Sun, 22 Feb 2004 20:36:05 -0800

Has anyone run into this before

When you execute an insert via ADO the RecordsAffected value comes back as 0 even when
the insert was successful. This was apparently caused by an insert trigger on the table which
contained a delete statement that effected 0 rows.
if I remove the delete statement or turn NOCOUNT on and off around it the RecordsAffected value is correct.

This is very easy to reproduce as the trigger does not need to actually do anything ie.

create trigger Test_1 on <some_table> for insert
if @@ROWCOUNT = 1
BEGIN
    delete <some_table> where 1=2
END

I was able to cause this problem with an update trigger as well

This does not occur in ODBC.



Relevant Pages

  • [NEWS] Multiple Vulnerabilities in Oracle Database (Trigger, Extproc, Wrapped Procedures, PL/SQL Inj
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Multiple vulnerabilities were discovered in the Oracle database server. ... Oracle Trigger Abuse ... written in PL/SQL and execute with the privileges of the definer/owner. ...
    (Securiteam)
  • Re: Stored procedure/trigger and scripts
    ... must have been the trigger that locked up the table. ... SQL Server has permissions to execute xp_cmdshell. ... >> client to change their password they have to call the "Client Relations" ...
    (microsoft.public.sqlserver.programming)
  • Re: Stored procedure/trigger and scripts
    ... I just ran some additional tests and it looks like my trigger is fine. ... SQL Server has permissions to execute xp_cmdshell. ... >> client to change their password they have to call the "Client Relations" ...
    (microsoft.public.sqlserver.programming)
  • Re: Best Practice - xp_cmdshell question
    ... execute from the trigger and use an alternate method. ... objects in an sa-owned database. ... >> without direct user execute permissions by changing your user database ...
    (microsoft.public.sqlserver.security)
  • Re: ADO + SQL-Server + Defaultwerte
    ... Ich kann ja bei ADO allgemein auch einen String mit einem SQL-Statement ... Der Trigger reagiert auf Updates und die zu ... behandelndeRowwirdanhand einer vorher auf dem Client ...
    (microsoft.public.de.vb.datenbank)