I have am X2025R3 web app sending email inside a webthread - which works just fine in that the emails get sent to AWS and arrive at the recipient OK.
However, if I put some code to write to a database (MariaDB via MySQLCommunityServer) where the db is defined on the session, I get nil object exeptions when trying to do anything to the database (db.begintransaction, for example),
The documentation indicates that webthread is session-aware, but this doesn’t seem to be the case. Am I missing something obvious?
It might be that there is no session. If the thread is launched from the App, and not from the session, then there is no session to connect to.
It’s better to give the thread it’s own DB connection anyways, in case the session or the app or any other thread is trying to use the DB at the same time.
In case this helps, the way webthread works is that when it is first created, it sets a string property to Session.Identifier. Whenever it goes to run your code, it sets up a context before calling the Run event:
Var context as new WebSessionContext(storedSessionIdentifier)
RaiseEvent Run
context = Nil