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.
you can solve this in several ways:
- create private unprotected DAService. you can use it as a local service for your TDALocalCommand.
- 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 := ServerDataModule.SessionManager.CreateSession(NewGuid);
LocalCommand.SessionID := fLocalSession.SessionID;
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?
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;
aLoginSuccessful := ACmd.ParamByName( ‘Result’ ).AsBoolean;
You can do it more easily w/o Schema object:
conn := ServerDataModule.ConnectionManager.NewConnection(...);
cmd := conn.NewCommand(...); // or conn.Dataset(...);
I like that even better. It’s much cleaner.