由于触发而被锁定在SQL Server之外

时间:2015-11-11 14:56:29

标签: sql sql-server database

我在SQL Server 2012上意外运行了以下触发器。如何撤消它?

触发器旨在阻止某些IP地址,但已阻止整个IP地址。我似乎无法登录任何地方。

CREATE TRIGGER block_ipaddress
ON ALL SERVER
FOR LOGON
AS
BEGIN
    DECLARE @capturedip NVARCHAR(15);

    SET @capturedip = (SELECT EVENTDATA().value('(/EVENT_INSTANCE/ClientHost)[1]', 'NVARCHAR(15)'));

    IF EXISTS(SELECT ipaddress FROM master.dbo.IPBLock WHERE ipaddress = @capturedip)
    BEGIN
        Print 'Your IP Address is blocked, Contact Administrator'
        ROLLBACK
    END
    ELSE
    BEGIN
        DECLARE @IPRange VARCHAR(15)

        SELECT @IPRange = SUBSTRING(@capturedip,1,LEN(@capturedip)-CHARINDEX('.',REVERSE(@capturedip)))+'.*'

        IF EXISTS(SELECT ipaddress FROM master.dbo.IPBLock WHERE ipaddress = @IPRange)
        BEGIN
            Print 'Your IP Address Range is blocked, Contact Administrator'
            ROLLBACK
        END
    END
END
GO 

我不再连接到数据库了。我从这个网站获得了这些信息: http://sql-articles.com/articles/security/ip-address-blocking-or-restriction-in-sql-server/

1 个答案:

答案 0 :(得分:4)

From the fine documentation

  

当登录触发器阻止连接时,成员   sysadmin固定服务器角色可以使用专用连接   管理员连接,或通过启动数据库引擎   最小配置模式(-f)有关详细信息,请参阅Database Engine Service Startup

然后一旦连接,您可以放下触发器。