Error: There are pending transactions.

I open a new window in SSMS and run this:

SET ANSI_DEFAULTS ON 
GO

CREATE PROCEDURE [dbo].[zzz_test2]
(
    @a    int
)
AS
    SET NOCOUNT ON
    SET @a=1
    RETURN 0
GO

and then close the window, which will cause this warning to appear:

There are uncommitted transactions. Do you wish to commit these before closing the window?

what's happening?

when I open a new SSMS window and run this:

SET ANSI_NULLS  ON  
GO    

CREATE PROCEDURE [dbo].[zzz_test2]
(
    @a    int
)
AS
    SET NOCOUNT ON
    SET @a=1
    RETURN 0
GO

and close the window, I do not receive a warning.

+5
source share
1 answer

As described in the documentation forANSI_DEFAULTS

When turned ON, this option allows the following ISO settings:

SET ANSI_NULLS
SET CURSOR_CLOSE_ON_COMMIT
SET ANSI_NULL_DFLT_ON
SET IMPLICIT_TRANSACTIONS
SET ANSI_PADDING
SET QUOTED_IDENTIFIER
SET ANSI_WARNINGS

As indicated here when IMPLICIT_TRANSACTIONSenabled.

Transactions that are automatically opened as a result of this setting must be explicitly set or rolled back by the user at the end of the transaction

+8
source

All Articles