Previous | Index | Next 

[INFO] Converted DataEnvironment instances open the connection only when needed

There is a minor difference between VB6 DataEnvironment classes and migrated VB6DataEnvironment .NET classes. The original VB6 DataEnvironment class opens all its ADODB connection as soon as it is instantiated; the migrated VB6DataEnvironment class opens the connection only when a command is actually executed.

In the majority cases, this difference doesn’t cause any problem and slightly improve overall performance. However, you must keep this detail into accout if you want to share the DataEnvironment’s connection with other ADODB object or you want to manually execute one of the DataEnvironment’s commands. Consider the following code:

  ' take a reference to a command exposed by the DataEnvironment
  Dim adoCmd As ADODB.Command 
  Set adoCmd = deCRM.Commands("cmdCustomers")
  ' manually execute it
  adoCmd.Execute

The above code works fine under VB6, because the Command object extracted from the DataEnvironment is associated with an open connection, but fails when the code is migrated to .NET, because no open connection has been associated yet with the Command object. You can account for this difference by opening the connection and associating it to the Command yourself, as shown in this piece of VB.NET code:

  ' take a reference to a command exposed by the DataEnvironment
  Dim adoCmd As ADODB.Command = deCRM.Commands("cmdCustomers")
  ' open the connection associated with the Data Environment
  deCRM_DefInstance.datNwind.Open()
  ' associate the connection with the command
  adoCmd.ActiveConnection = deCRM_DefInstance.datNwind
  ' manually execute it
  adoCmd.Execute()

 

Previous | Index | Next