Tip for those using Firebird and UniDac with Aurelius in adapter mode

Long Story short:

This post is about preventing the Bcl.Json.Reader.EJsonExpectedValue exception when using Firebird with UniDac in Aurelius adapter mode.
The Error can be avoided by setting the EnableMemos option to True in the Options tab of the design time connection editor of the TUniConnection component

Some more details:

Yesterday I spent nearly half a day debugging Aurelius and Sphinx source code and here I just want to share the outcome to help others which might run into the same problems that I did.

It all started with trying to make the SphinxSimpleDemo (which comes with the TMS Sphinx component set) run with a Firebird database using the devart - UniDac Components in Aurelius adapter mode instead of the SQLite db in Aurelius driver mode, which the demo project uses by default.

Then I ran into the problem:

Turns out, there’s a thing to know about how to configure the TUniConnection component to work flawlessly with the SphinxSimpleDemo (and Aurelius in general when using text blob fields).

Initially I created a new Firebird db with charset set to UTF8 and set the connection information in the TUniConnection to point to that db and on the Options tab of the TUniConnection connection design time editor I changed the „Charset“ to UTF8 and „UseUnicode“ to True and configured that connection to be used with the AureliusConnection in adapter mode.
With these settings the SphinxServer created the needed tables with the initial records for the default users correctly. However logging in with the VclClient or the WebClient was not possible and always resulted in the display of the following error message instead of the expected login form in the web browser:

{
    "error": {
        "code": "JsonExpectedValue",
        "message": "Value expected but invalid character found at $"
    }
}

After a while of debugging Sphinx and Aurelius source code, I found that

  • all data is stored in the firebird db correctly as it should
  • reading back records from the db table sx_storage_items results in a wrongly encoded „Data“ property in the Sphinx.Entities.TDBStorageItem class. Turns out this property is annotated with the [DBTypeWideMemo] attribute.

Solution:

Setting the EnableMemos option to True in the Options tab of the design time connection editor of the TUniConnection component is crucial and prevents the problem from happening.
This EnableMemos option has been introduced a couple of years ago in the devart UniDac TUniConnection and changed a former default behavior. So if you use a recent UniDac version, you need to set that option to true in order to use Sphinx with Firebird and UniDac.

This is also valid for all your Aurelius projects (with Firebird and UniDac) when you use Entities with properties annotated with the [DBTypeWideMemo] attribute. These properties result in text blob fields in the firebird db and without the EnableMemo option set to true, reading back those values result in string encoding corruptions.

I finally want to point out that it has been of great help, that TMS components are delivered with full source code, otherwise it would have been very hard to nearly impossible to find this issue in a structured way. So thank you TMS for your way of delivery.

Hi @Suer_Martin, thank you very much for your contribution. Really appreciated.