Does a connection instance need to be created in ObjectContext?

Viewed 57

We have old VB6 code in our production system that everyone is afraid to touch. But, occasionally, a bug is large enough that someone needs to fix it. We are in the process of rewriting the system, but in the meantime, we still have customers using the existing VB6 code.

My biggest issue right now is my lack of understanding about ObjectContext. I've been reading documentation about it, and the more I read, the less I understand. I see code where sometimes, we have a block that looks like this:

Set CtxObject = GetObjectContext

If Not CtxObject Is Nothing Then
    Set objSomeObject = CtxObject.CreateInstance("SomePackage.SomeObject")
Else
    Set objSomeObject = CreateObject("SomePackage.SomeObject")
End If

but, ADODB.Connection objects are never created like this. Should connection objects be created like this? If the objContext is aborted, will any updates through that connection be rolled back? Or not since they were not created within the same object context?

Example of how we do create connection objects:

Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.RecordSet
On Error GoTo ErrorHandler
Dim CtxObject As ObjectContext
Set CtxObject = GetObjectContext

oConn.Open *ConnectionString*
oRS.Open *SQL*, oConn, adOpenKeyset, adLockBatchOptimistic

...

Here, the connection object is created before the object context is grabbed, so I don't see how the connection is tied to that. If the RecordSet is updated, and then the ObjectContext is aborted, will the RecordSet updates be rolled back?

0 Answers
Related