Good morning to all,
in a little mobile application is not rare that an error, diring request data (query execution), happend.
The message error is
'RemoteDB request error: '#012'http://xxx.xx.xxx.xxx:2001/tms/remotedb/openfields'#012'491'
Where xxx is real ip address
491 is a code error used on server side in this procedure
procedure StartServer;
var
Module : TRemoteDBModule;
aes : TAESEncryption;
begin
if Assigned(SparkleServer) then
Exit;
SparkleServer := THttpSysServer.Create;
Module := TRemoteDBModule.Create(
'http://+:2001/tms/remotedb',
TFireDacFirebirdConnection.CreateFactory
);
Module.AddMiddleware(TBasicAuthMiddleware.Create(
procedure(const UserName, Password: string; var User: IUserIdentity)
begin
if (Edt1.Text<>UserName) then
Begin
User:=Nil;
Errorcode:=490;
End
Else
if (Edt2.Texrt<>UserPassword) then
Begin
User:=Nil;
Errorcode:=491;
End
Else
Begin
User := TUserIdentity.Create;
User.Claims.AddOrSet('UserName').AsString :=Edt1.Text;
User.Claims.AddOrSet('Password').AsString:=Edt2.Text;
End;
end,
'My Server Realm'
));
Module.AddMiddleware(TAnonymousMiddleware.Create(
procedure(Context: THttpServerContext; Next: THttpServerProc)
begin
if Context.Request.User = nil then
begin
// no user authenticated, return error 401
Context.Response.StatusCode := ErrorCode;
Context.Response.ContentType := 'text/plain';
Context.Response.Close(TEncoding.UTF8.GetBytes('User not authenticated'));
end
else
Next(Context);
end
));
Module.UserName:='';
Module.Password:='';
// Uncomment line below to enable CORS in the server
//Module.AddMiddleware(TCorsMiddleware.Create);
// Uncomment line below to allow compressed responses from server
//Module.AddMiddleware(TCompressMiddleware.Create);
SparkleServer.AddModule(Module);
SparkleServer.Start;
end;
The error occoures in unti RemoteDB.Client.Database, in procedure procedure TRequestPerformer.Request(const Path: string) at this source level
if not IgnoreError then
begin
ErrorMessage := Format('RemoteDB request error: ' + sLineBreak + '%s' + sLineBreak + '%d',
[Req.Uri, FResp.StatusCode]);
case FResp.StatusCode of
401:
ErrorMessage := ErrorMessage + sLineBreak + 'Authentication failed.';
410:
ErrorMessage := ErrorMessage + sLineBreak + 'Database instance lost during transaction.';
500:
if SameText(FResp.ContentType, 'text/plain') and true {DetailedException} then
ErrorMessage := ErrorMessage + sLineBreak + TEncoding.UTF8.GetString(FResp.ContentAsBytes);
end;
raise ERemoteDBRequestException.Create(FResp.StatusCode, ErrorMessage); <<<<---- here !!
end;
If i lunch the same query 30 times, this error happend 4-5 times ... and i do not for which reason.
Also how i can set IgnoreError to true before luncg the query and false after done it !!
The query is lunched via XDataSet.Sql.Add(querystr) and XDataSet.Active:=True.
Any suggestion on how to resolve this case ??
Thank's for the attention
Regards
Daniele