2

I would like to create a SQL Server 2005 user account but limit that user to only allow them to have two concurrent connections to the database at once. Is there any way to do this through SQL Server configuration?

Mindy
  • 117
  • 2
  • 2
  • 8

1 Answers1

8

You could try Login Triggers: http://technet.microsoft.com/en-us/library/bb326598.aspx

TechNet suggests that:

You can use logon triggers to audit and control server sessions, such as by tracking login activity, restricting logins to SQL Server, or limiting the number of sessions for a specific login.

Their first code example limits a user to 3 connections (Quoting TechNet):

USE master;
GO

CREATE LOGIN login_test WITH PASSWORD = '3KHJ6dhx(0xVYsdf' MUST_CHANGE,
    CHECK_EXPIRATION = ON;
GO

GRANT VIEW SERVER STATE TO login_test;
GO

CREATE TRIGGER connection_limit_trigger
ON ALL SERVER WITH EXECUTE AS 'login_test'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'login_test' AND
    (SELECT COUNT(*) FROM sys.dm_exec_sessions
            WHERE is_user_process = 1 AND
                original_login_name = 'login_test') > 3
    ROLLBACK;
END;
Tim Santeford
  • 278
  • 3
  • 7