Limit number of users in c# application

I am developing a Client-Server application using C#. Basically the server is a SQL server and the clients are developed in C#. What I would like to know is the best way (if any) to limit the number of users using the application at any one time - say I wish to limit to two users. Would I limit their access to SQLserver?


You will potentially need the concept of a "session" to identify the concurrent number of users.

If want this to be done in a fail-safe manner, you will have to introduce an application layer between your DB server and the client. You can then provide methods to login and logoff for users.

At every login you will need to increment a count of "concurrent users" and at every logoff you will need to decrement.

You may need to introduce the concept of session time-out as the some of the clients may shutdown without invoking the logff method.

The number of concurrent users allowed can be associated with a license.


Use "currentUser" table to store current users logging into the system concurrently.

When the user login, check the row count if the max no. of rows has reached.

Remove the respective row when the user leaves the system. In that way, you may also restrict using the same user ID to login from different computers as well.


You could simply sell individual licences.

Create the application in a way that it checks its licence on a trusted server (could be the SQL Server).

Sell a licence per computer/user.

This way you could easily scale to more than 2 users if needed.

It is also possible to implement floating licences: everytime a user tries to obtain a licence it is only given when available. Of course the licence will have to be 'freed' after a disconnect or time-out. In this scenario you need a server that contains a number of licences and a trusted service that hands them out.

In the Winforms application you would simply check for the licence on startup and you could extend the timeout everytime the user does something significant (such as querying the database or clicking a menu item)

链接地址: http://www.djcxy.com/p/11632.html

上一篇: 在C#中强制约束泛型类

下一篇: 限制c#应用程序中的用户数