SQL Server中的登录触发器概述

本文介绍了SQL Server中的登录触发器,用于控制和审计SQL Server的身份验证。登录触发器在用户登录时执行,允许DBA限制连接数、控制特定时间段的连接和审计登录事件。示例展示了如何限制连接总数、按用户限制连接和限制特定时间的登录。此外,还讨论了登录触发器的使用注意事项和回滚计划的重要性。
摘要由CSDN通过智能技术生成

This article gives you an overview of Logon triggers in SQL Server and its usage to control SQL Server authentication.

本文为您概述了SQL Server中的登录触发器及其在控制SQL Server身份验证中的用法。

介绍 (Introduction)

SQL Server provides Windows and SQL authentication method to connect using SSMS or client applications. Security is always a primary focus for DBA, especially in the production environment. We can control database access by providing minimum and appropriate permissions for user work. We can use GRANT or DENY statements in SQL Server to give appropriate task permissions for the individual user.

SQL Server提供Windows和SQL身份验证方法,以使用SSMS或客户端应用程序进行连接。 安全始终是DBA的主要重点,尤其是在生产环境中。 我们可以通过为用户工作提供最小和适当的权限来控制数据库访问。 我们可以在SQL Server中使用GRANT或DENY语句为单个用户赋予适当的任务权限。

SQL Server has the following triggers:

SQL Server具有以下触发器:

  • Data Definition language triggers or DDL riggers

    数据定义语言触发器或DDL绑定器
  • Data Manipulation Language or DML triggers

    数据处理语言或DML触发器
  • Common language runtime or CLR triggers

    公共语言运行时或CLR触发器
  • Logon triggers

    登录触发器

In this article, we will explore Logon triggers in SQL Server and its usage.

在本文中,我们将探讨SQL Server中的登录触发器及其用法。

SQL Server中的登录触发器 (Logon triggers in SQL Server)

Triggers is a database code that gets executed in case of a precisely defined event. We can use logon triggers to control the SQL login security. SQL Server automatically executes the logon triggers once a logon event occurs. It gets executed before a user session is established and authentication is successful.

触发器是在精确定义的事件下执行的数据库代码。 我们可以使用登录触发器来控制SQL登录安全性。 登录事件发生后,SQL Server将自动执行登录触发器。 它在建立用户会话和身份验证成功之前被执行。

We use two terms for a database successful connection in any database.

对于任何数据库中的数据库成功连接,我们使用两个术语。

  • Authentication: We specify a username and password to connect using SQL authentication. It is a validation of the user’s credentials 身份验证 :我们指定用户名和密码以使用SQL身份验证进行连接。 这是对用户凭据的验证
  • Authorization: It is a permission that allows you to do specific tasks. You may be authorized to have full access to a specific database but not authorized to make any changes at the instance level 授权:允许您执行特定任务的权限。 您可能被授权拥有对特定数据库的完全访问权限,但无权在实例级别进行任何更改

Logon Trigger integration

If any user is unable to authenticate to SQL Server (wrong credentials), SQL Server does not execute the logon triggers. SQL Server starts an implicit transaction before the logon triggers fires. It is independent of any user transaction. In the case of the logon trigger, the transaction count is 1. In case SQL returns an exception, its value sets to zero. It fails the implicit transaction, and the user session is not established. User connection also fails in case of the error having severity more significant than 20 inside the trigger.

如果任何用户无法通过SQL Server进行身份验证(使用错误的凭据),则SQL Server不会执行登录触发器。 SQL Server在登录触发器触发之前启动隐式事务。 它独立于任何用户事务。 对于登录触发器,事务计数为1。如果SQL返回异常,则其值设置为零。 它使隐式事务失败,并且未建立用户会话。 如果错误在触发器内部的严重性大于20,则用户连接也会失败。

Let’s explore the use of cases of logon triggers using examples.

让我们使用示例探讨登录触发器的用例。

使用SQL Server中的登录触发器限制SQL Server连接的总数 (Restrict the total number of SQL Server connections using Logon triggers in SQL Server)

Sometimes, we require to restrict the total number of SQL Server connections. Too many connections might cause performance issues so we can use logon triggers to solve this purpose. By default, SQL Server allows an unlimited number of concurrent connections to SQL Server. You can verify it in the SQL Server properties.

有时,我们需要限制SQL Server连接的总数。 太多的连接可能会导致性能问题,因此我们可以使用登录触发器来解决此目的。 默认情况下,SQL Server允许无限数量的并发连接到SQL Server。 您可以在SQL Server属性中进行验证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值