Monday, March 28, 2011

Limiting Users for a Database

Advantage counts users based on the machine name that is connecting. This means that a single machine can have multiple connections to Advantage while only consuming a single license.  There are times when you may wish to limit the number of users to a particular database. For example you may be hosting data for multiple customers at your site or in the cloud. You may need a way to limit each customer to a specific number of concurrent users. If each customer has a specific database you can accomplish this by using the sp_mgGetTableUsers system procedure when your application starts up.

The sp_mgGetTableUsers procedure takes one parameter which is the full qualified path to the table. You can provide a path to a data dictionary instead of a table to get a list of all the users connected to the database. See the example below

sp_mgGetTableUsers1

As you can see this list returns all connections to the specified file. You will need to count the results based on the type of users you wish to track. If you are using a traditional client/server solution where each user has their own machine name ( as shown in the example ) you need to count the number of unique UserName values. If you are hosting the application on a terminal server then you will need to count the unique TSAddress values.

If you are using Advantage version 10 or newer you can use SQL to count the connections. The example below demonstrates different types of counts.

sp_mgGetTableUsers2

By running a script like the one above when your application starts you can get an accurate count of the total number of users connected to the specified database. You could then compare this to the number of licenses for that database. The number of licenses could be stored encrypted in the registry, in a license file or some other method.

There are a few limitations to this approach. This technique will not prevent third party applications since the check is done by your application and not by the server. This technique will also not work for a web based application since all users will be connecting through one or more web servers.

1 comment:

synack said...

The TS column looks suspect. 0.0.0.0 isn't a valid address and it counts one but there really are 0.