INsert from an SP

  • When I execute the following:

    insert ##jay execute sp_change_users_login 'report' 

    I get:

    Terminating this procedure. Cannot have an open transaction when this is run.

    Any body have any ideas why this will not populate my temp table? (I have allerady created the temp table for the session, I did not include the code fot it for simplicity sake).

    -JG


    -JG

  • The default mode for SQL Server is to open a transaction for each individual Transact-SQL statement. This transaction is automatically committed when the statement completes.

    Since the 'sp_change_users_login' explicitly states

    quote:


    -- ERROR IF IN USER TRANSACTION --

    if @@trancount > 0

    begin

    raiserror(15289,-1,-1)

    return (1)

    end


    It aborts with error message '15289'.

    Regards, H.Lindgren

  • Execute SELECT @@TRANCOUNT to see if there is an opened transaction. If you get <> 0 then close it with commit or rollback (this is up to you), and then re execute your insert.

  • Lingrend,

    So the insert is a transaction and the SP notices the open tran and aborts?

    Is the work around to edit the sp itself and modify the trancount value?

    -JG


    -JG

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply