0

If one instance of Datasnap server is running, trying to open another one crashes this second instance. How can you prevent users from opening more than one instance of datasnap server?

On create of the server application :

Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TServerContainer1, ServerContainer1);
  Application.Run;

I tried putting LMDOneInstance on the Form1 but the server still keeps opening another instance (visible in the windows task manager). It does not crash the newly created instance but it just creates another process.

enter image description here

user763539
  • 3,509
  • 6
  • 44
  • 103
  • 1
    When you say "trying to open another one", do you mean "trying to launch another instance of the server"? The reason I ask is that I am not clear why you would allow end users to launch the server in the first place ... – MartynA Dec 08 '13 at 18:42
  • Create a global Mutex (SyncObjs.TMutex) to check if there is already an instance running on the computer – Sir Rufo Dec 08 '13 at 19:10
  • MartynA - It's not going to happen (I hope so) but just in case ... – user763539 Dec 09 '13 at 11:55
  • @user763539. The best way to avoid it is not to allow them execution access to the server. – MartynA Dec 09 '13 at 12:06
  • @MartynA is right. Trying to stop users doing this just obfuscates your code. Tell them not do it. – David Heffernan Dec 09 '13 at 14:35

1 Answers1

0

Put a JvAppInstance on a data module, and it will handle the rest.

iMan Biglari
  • 4,674
  • 1
  • 38
  • 83