Question

I have this following scenario: A database with user login table. A c# desktop application. What I do is when I login I set the login flag to true for that user in database and when the user log off or quits the application I change that flag back to false. This work perfect, but when the power failure occur or someone just kill the application process the flag remain true hence not allowing to sign in again and displays the message "you are already login" How do I should manage this?

Was it helpful?

Solution

@Mike of SST is right, but for some reason of yours,

You can do the following

  1. Add another column along your [Login] flag, say DateTimeOfLogin value of when the user has been logged
  2. On your application side, add a function that periodically (says every 10 secs or as you preferred) updates that DateTimeOfLogin column (for optimum performance use thread on this)

When the user try to re-login and the [Login] flag is true and the difference between DateTimeOfLogin value is more than 10 secs then it means either your application is terminated or not properly shutdown or a power failure has been occured.

OTHER TIPS

Don't bother with the flag. If the user has access to the tables, so that application can read the flag, then they must be logged in!

The Database server will manage the connection for you.Your application will provide appropriate connection strings and your security policy will require (or not) user names, passwords, etc. Visual Studio fills in good working code to handle all of this when you add the database to your project as a data source.

During the runtime of a single session of the desktop application, the connection with the server may be established and dropped multiple times. Just let the framework handle it for you: keep it simple.

If you need the information to be available outside the user's desktop application (e.g. to other users of the database) then you will need to implement rules on the database side, rather than in the client code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top