#1 2026-01-16 15:05:42

larand54
Member
Registered: 2018-12-25
Posts: 126

How to create a server from IRestOrmServer

Obviosly I can not do like this:

// Some declarations:
  private
    fModel: TOrmModel;
    fDBServer: IRestOrmServer;
    fProps: TSqlDBOleDBConnectionProperties;

The init code:
  fModel := CreateLOBModel;
  ConnectDB(LOBMonSetupRec.DBServer, LOBMonSetupRec.Database, LOBMonSetupRec.UserName, LOBMonSetupRec.PassWord);
  VirtualTableExternalRegister(Model, TSQLLobUserControllv2, fProps, 'dbo.LobUserControllv2');
  VirtualTableExternalRegister(Model, TSQLLob_GroupUsers, fProps, 'dbo.Lob_GroupUsers');
  VirtualTableExternalRegister(Model, TSQLLobGroupDtl, fProps, 'dbo.LobGroupDtl');
  
  rs := TRestServerDB.Create(Model);
  fDBServer := TRestOrmServer.Create(rs); // Gives the exception: First chance exception at $77171E94. Exception class ERestException with message 'TRestServerDB.SetOrmInstance twice'.

// Never reach this  part cause of the exception
  DBServer.CreateMissingTables;

I can not use the TRestServerDB instance when I creates the fDBServer as both calls SetOrmInstance so, what type should I use?


Delphi-11, WIN10 and Win11

Offline

#2 2026-01-16 15:35:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,383
Website

Re: How to create a server from IRestOrmServer

No, this is clearly incorrect.
You don't call TRestOrmServer.Create by yourself.
You initialize TRestServerDB then you use the IRestOrm as interface, from TRestServerDB.Orm or IRestOrmServer from TRestServerDB.Server!

This is clearly documented as such.
I tried to make it even more explicit:
https://github.com/synopse/mORMot2/comm … 0957f36816

Offline

#3 2026-01-16 15:57:30

larand54
Member
Registered: 2018-12-25
Posts: 126

Re: How to create a server from IRestOrmServer

Ok, I think I understand so I did like this:

  fDBServer := TRestServerDB.Create(Model).Server;

And that made it!

Sorry but I have obviosly very hard to finds things in the doc. I always try to find things in the source and mostly I find it there but not too often.


Delphi-11, WIN10 and Win11

Offline

Board footer

Powered by FluxBB