DALocalCommand from Login service

I am trying to use a stored procedure from within the login service’s OnLogin event handler. I have tried using the TDALocalCommand class, but I keep getting a session not found error.

I was wondering how to handle this as at that time there really isn’t a session yet.

Hi,

you can solve this in several ways:

  • create private unprotected DAService. you can use it as a local service for your TDALocalCommand.

or

  • create session manually. later you can use this as a session for your TDALocalCommand so it can use protected DAService.
    You can create session as
// fLocalSession:TROSession;
  fLocalSession := ServerDataModule.SessionManager.CreateSession(NewGuid);
  LocalCommand.SessionID := fLocalSession.SessionID;
  ServerDataModule.SessionManager.ReleaseSession(fLocalSession, True);
  

Hello,

Do you possibly have an example of how to use the database with the Login service?

Or possibly an example of how to create a private unprotected DAService for use with login?

Thanks

I found the best way to create the login routine is to add a schema to the login service and then use the NewCommand method of the schema.

var ACmd := Schema.NewCommand( Connection, ‘IsValidLogin’, ‘IsValidLogin’, ‘ElevateDB’ );

ACmd.ParamByName( ‘UserID’ ).AsString := aUserID;
ACmd.ParamByName( ‘Password’ ).AsString := aPassword;

ACmd.Execute;

aLoginSuccessful := ACmd.ParamByName( ‘Result’ ).AsBoolean;

Hi,

You can do it more easily w/o Schema object:

  conn := ServerDataModule.ConnectionManager.NewConnection(...);
  cmd := conn.NewCommand(...); // or conn.Dataset(...);
  cmd.Execute;

Thanks Evgeny,

I like that even better. It’s much cleaner.