Thom McGrath wrote:
That won't work, the instance would still be shared between all sessions. You have one instance for each time you use the keyword "new".
As for the SMTP class, I would put that on App. It is impossible for two calls to happen at the same time, as only one line of code can execute at a time. There is no advantage to making one connection per session in that case.
The main reason you want one database connection per session is transactions. Since loop boundaries can trigger thread context switches, you want to be certain that all related queries are encapsulated together. Otherwise, you can find yourself in serious trouble.
Tim is absolutely correct about Session being a function though. It is an expensive function, as it has to map the current thread to a session object. It does this using dictionaries, but it still has to determine the current thread, and all that. So if you need to make even a few calls to Session in the same method, use a temporary variable. This is one of my favorite lines of code, because it's perfectly legal despite looking completely insane:
Dim Session As Session = Session
That simple addition can make a world of difference.
Sorry, re-reading this and had a couple of questions.
In ColdFusion, you defined the DB connection in the CF Administrator and done. Your code, when called, uses that connection. You can lock the app for brief moments when executing updates if needed. Or you can code a record lock if needed. But, it's one connection point to the DB.
With WE, you need to have a connection for each client? We have thousands of simultaneous users, this would result in thousands of connections to the DB? These connections are maintained? That seems very inefficient and an easy way to overload you DB server.
Again, just trying to get my head wrapped around the differences.