Problem running an SQL Update query in a table script using CreateQueryObj() Exec()

SOLVED

Hi all, I have a problem running a query to update a Company record from inside of the Comm_Link (secondary) entity. The query starts in Comm_Link > grabs Communication details > grabs Company details > updates a new custom field in the Customer entity.

The query runs on a local version I have installed without proble, , but when it is being put live it times out. I get a  SafeCall Exception:SQL Error in the log (with no other explanation) and the update doesn't run. I have enabled the log() function which tells me the query is timing out. Pulling the SQL that is generated out and running it on the server runs without problem, assuming the CRM database has been selected and is in scope. I have tried using fully qualified names for the database table and still it proves problematic. I have also tried running a update query on other custom fields, but this fails.

One thing to note is SQL server / the db exists on a different physical server to the CRM install. I have read that this could cause problems and I might need to pass a database name as a second argument to the CreateQueryObj() to get it to work. I can't find any documentation on forming the string to pass it, nor can I find examples, and the few examples I have tried are likely wrong.

The database is registered successfully as the default database within Sage CRM however. 

The code running looks like the following:

var sql = "UPDATE Company SET Company.comp_NextCallDue = '" + dateAsString + "' WHERE Company.comp_companyId = " + companyId;
var updateCompanyQuery = CRM.CreateQueryObj(sql"CRM");
updateCompanyQuery.ExecSQL();
dateAsString looks like '2020-10-09 00:00:00.000' and is a date only field. 

Any help or suggestions would be gratefully appreciated. 

Best regards, Paul