The Audit Log can actually give you that information already.  If you audit Login and Logout events you can then use SQL to see what's going on in the system.  Here's a query to get started (in the %SYS namespace):

SELECT UTCTimeStamp,Username,Event
 FROM %SYS.Audit

I recommend you open an issue with the WRC.  We'd be happy to help you out here.

While Gilberto's answer is right, I would file this under "not the purpose of SQL".   While there are many things you can do with SQL, the purpose of SQL is not to administer Caché/IRIS users.  You are much better off using the Management Portal or one of the accepted APIs. 

Alas, I'm going to be out of the office for the next two weeks, so I won't be able to answer questions on this video.  But I'll try to remember to come back to it when I'm back in the office on 2018-06-11.  Hope you all enjoy this as much as I hate hearing the sound of my own voice!

I'd bet my breakfast that your first line of code connects to a remote database, and that is failing.  Therefore, when you go to prepare your query, it is failing due to no connection.  Check the status code from your Connect() call and let us know what that says.

For an ACTUAL solution to your question - go to the SMP and to System Administration->Configuration->(CSP/Web) Gateway Management.  From there go to 'Default Parameters'.  The timeout you want to change is the Server Response Timeout.  If you are using the private apache you can also edit the CSP.ini file in <Install>/csp/bin/.  Of course, if this is a Production Systems DO NOT DO THIS OR I WILL FIND YOU AND SAY VERY MEAN THINGS!

Your IIS configuration maps /csp to the CSP Gateway, but your application is /myapp - so when IIS looks at /myapp, it doesn't know what to do so it tries to serve files off of your filesystem which, of course, it can't!

So your question now, no doubt, is why does it work through the private Apache server (57773)?  Well because the private Apache server is set up to ALWAYS send ALL requests to the CSP Gateway, and the CSP Gateway knows how to handle it.

There's another trick, too.  When you create your /myapp virtual application, make sure you create a new module mapping for *. REST requests do not have extensions so you need to be sending all requests to the CSP Gateway regardless of extension (or things won't work)!

If you are having any more trouble getting this set up, please feel free to contact the WRC and we'll be happy to help you get set up.  

The advice you have received thusfar has been OK, but the easiest thing to do would be to watch Mike Smart's global summit presentation, which takes you from literally nothing, to having a (nearly) fully fleshed out REST API in a simple case.  See that here:

If this is your first time working with REST Applications, this is the best place to start.  Then, if you'd like, you can continue with an online learning course, where Mike is going to expand on this to include some best practices.  Announcement for that is here:

Hopefully we'll see you there!