Hi @Dan Trifan
I found this thread for you that talks a lot about "RESTORE cannot process database...": https://social.msdn.microsoft.com/Forums/sqlserver/en-US/37ee8e24-7aaa-472b-861a-fc0cc513338a/unable-to-restore-database-quotbecause-it-is-in-use-by-this-sessionquot?forum=sqltools.
There is also a document on backing up and restoring databases and transaction logs with SMO here: https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/tasks/backing-up-and-restoring-databases-and-transaction-logs?view=sql-server-ver16.
Hope these can help you.
Best regards,
Aniya