This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi In my application i have a loop which on external reuest loops over a certain table in the DB, say 'Units', and if a unit does not satisfy a specific condition, or seem un-updated sends an SMS to this unit. I do this by querying on the table and then using 'foreach' (C#) iterate on the results. Since this process might be somewhat lenthy, although SMS messages are put on worker thread, and i want to avoid DB connectivity issues (hardware for example) i looked for connection testing and closable connections. I came across an article, i think by Ivan that demonstrates a 'closableconnectionstrategy' class, the bottom line was - close your connection after a reasonable time, lightspeed will open it when neccessary. My question is - if i have a query object, and the connection is closed and then reopened, what happens to this query. example (partial): uow.ConnectionStrategy = new CloseableConnectionStrategy(_context); // assign the closable connection strategy I will appreciate any insight or explanatioin best regards doron |
|
|
Because you are using LINQ, the actual execution of the query takes place when you start enumerating unitsQry with the foreach statement. At that point all results are materialised and are stored in-memory, so the remainder of the enumeration takes place over the in-memory list so it wont impact you enumerating the rest of the list. If you want to exit the loop at that point you will want to break out of the loop after you close the connection. In terms of how the connection strategy operates, where one is present we use this to obtain the connection, so your implementation of the Connection property is your opportunity to decide how the connection is managed (and as you have in your code above, you can also control when it gets closed). We just expect an open connection to operate on.
|
|
|
Thanks for your reply, |
|
|
Because you are using a custom connection strategy we will use the value given to us when accessing the "Connection" property, so its up to you to ensure that an open connection is returned. If you are closing the connection your Connection property will probably want to validate the connection is in a closed state and then reconnect as required as part of its implementation.
|
|