SQL Server Session-Count Permissions¶
Added in Flex2SQL 18.1. Applies to the MS SQL driver.
Flex2SQL needs to count its active SQL Server sessions for license/user-count checks. Querying SQL Server session information directly requires server-state permissions. Giving those permissions to an ordinary application login also allows access to server-wide diagnostic information beyond the driver’s count.
The Driver Module Signer provides a narrower alternative. It installs
a signed stored procedure in master that returns the count needed by the
driver. The certificate-based login receives the server-state permission;
application users receive permission to call and inspect the signed procedure
through a dedicated database role.
Use this when deploying applications with restricted database logins or when
a session-count check reports that a login cannot query
sys.dm_exec_sessions. Application logins do not need to be made SQL Server
administrators or directly granted broad server-state permissions to use this
mechanism.
What Is Installed¶
The setup creates:
master.dbo.f2s_ms_DriverSessionInfo, the signed counting procedure.f2s_ms_DriverModuleSigner, its certificate inmaster.f2s_ms_DriverModuleSignerLogin, a certificate-based server login.db_role_f2s_ms_DriverSessionInfo, a database role inmaster.
The certificate-based login receives VIEW SERVER PERFORMANCE STATE on
SQL Server 2022 and later, or VIEW SERVER STATE on earlier versions.
The application role receives EXECUTE on the procedure and
VIEW DEFINITION on the procedure and certificate, allowing the driver
to verify the expected signature before using it.
This is an instance-level setup in master; it is not a migration of an
application table. A DBA must perform setup using a login authorized to create
the procedure, certificate, server login, role, and associated grants.
Ordinary application logins only need the runtime role membership described
below. The deployment must permit these objects in master and the
certificate-based server login.
Enable It in the Migration Utility¶
Open the Flex2SQL Unicode Migration Utility and log in to the target SQL Server using the administrative setup login.
Choose File > Driver Module Signer > Create Module Signer. The submenu is enabled only while logged in using the MS SQL driver. Create is enabled when the expected signer is not detected.
Wait for the success message. The procedure, certificate, certificate-based login, and role are now installed.
Have the DBA add the application’s user in
mastertodb_role_f2s_ms_DriverSessionInfo. Creation does not automatically add application users to the role.Reconnect using the application’s normal login and verify that the driver can perform its session-count check. Testing only with the administrative login does not verify the application’s permissions.
Role Membership¶
Membership is assigned to a database user in master, not directly to a server login. If the application login does not already have a mapped user there, the DBA must create one first.
For an existing server login named OrderEntryLogin, the following example
creates a mapped user and adds it to the role. Run the CREATE USER statement
only if that user does not already exist; otherwise use the existing mapped
user’s name in ALTER ROLE.
USE [master];
GO
CREATE USER [OrderEntryUser] FOR LOGIN [OrderEntryLogin];
GO
ALTER ROLE [db_role_f2s_ms_DriverSessionInfo]
ADD MEMBER [OrderEntryUser];
GO
Repeat the membership step for each application identity that needs to use the
procedure. Adding a user to a similarly named role in an application database
does not grant access to the role in master.
Programmatic Setup and Status¶
The same operations are available through these 18.1 commands:
f2s_get_driver_module_signer_status {ServerName} TO {Status}
f2s_create_driver_module_signer {ServerName}
f2s_delete_driver_module_signer {ServerName}
The MS SQL driver must be loaded and active, and a connection to
ServerName must already exist. Pass the same server/connection name used
when logging in. Use the 18.1 f2s.pkg and driver.
The status command returns 1 when the expected signed procedure is
verified. 0 means it could not be verified: it may be missing, have an
unexpected signature, or be inaccessible to the current user. Check Err
for command failures and investigate access problems before treating
0 as proof that setup has never been performed.
Use the create and delete commands as administrative setup operations. Creating the signer can replace existing signer objects; do not call it on every application startup. Successful creation still requires the separate application-user role membership step.
See the command references for syntax and examples:
Troubleshooting and Removal¶
If session counting still fails:
Confirm that setup was performed on the same SQL Server instance used by the application.
Check the application’s mapped user and role membership in
master.Check that the application user can inspect the procedure and certificate as well as execute the procedure.
Run the status command using the application login. Status
1verifies the signature but is not by itself a test that execution will succeed.Collect an errors-only trace for the failing login. A generic message suggesting a direct
VIEW SERVER STATEgrant can also indicate that the signed-procedure path is unavailable; check this setup.
Do not modify the installed procedure’s definition: the driver checks its expected signature. Use the supplied setup operation to recreate it if needed.
To remove it, use File > Driver Module Signer > Delete Module Signer or f2s_delete_driver_module_signer with an administrative connection. The utility enables Delete when it detects the expected signer. Removal drops the procedure, certificate-based login, and certificate; it does not remove the database role or its memberships. Applications relying on the signer will no longer be able to use that session-count path.