I have been getting a lot of questions on Upgrading and thought I would check to see if the VS 2005 Upgrade Wizard is capable of doing COM+ objejcts as unfortunately the article What's New with the Visual Basic Upgrade Wizard in Visual Basic 2005 skirts this topic.  Long story short the current builds of Visual Studio 2005 still doesn’t upgrade COM+ applications –but it is closer!

 

Starting with the VB 6.0 code:

 

Public Function send_promo(str_param As String, COM As String) As String

Dim Rs1 As New ADODB.Recordset

Rs1.Open "select * from sysobjects", "Provider=SQLOLEDB.1;Data Source=chass;uID=sa;pwd=xxx;Initial Catalog=NorthWind"

Dim context As COMSVCSLib.ObjectContext

Set context = GetObjectContext

If COM = "Y" Then

    context.SetComplete

Else

    context.SetAbort

End If

Set Rs1 = Nothing

End Function

 

This is upgrade to:

 

<System.Runtime.InteropServices.ProgId("Comclass_NET.Comclass"), System.EnterpriseServices.Transaction(TransactionOption.Supported)> Public Class Comclass

      Inherits System.EnterpriseServices.ServicedComponent

      Public Function send_promo(ByRef str_param As String, ByRef COM As String) As String

            Dim Rs1 As New ADODB.Recordset

            Rs1.Open("select * from sysobjects", "Provider=SQLOLEDB.1;Data Source=chass;uID=xxx;pwd=sa;Initial Catalog=NorthWind")

            Dim context As System.EnterpriseServices.ContextUtil

            'UPGRADE_ISSUE: COMSVCSLib.AppServer  .GetObjectContext was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/redir/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'

            context = GetObjectContext

            If COM = "Y" Then

                  context.SetComplete()

            Else

                  context.SetAbort()

            End If

            'UPGRADE_NOTE: Object Rs1 may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/redir/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'

            Rs1 = Nothing

      End Function

 

Which is SO close!

–The project even has an SNK key in the assembly file to give the assembly a strong name!  If the wizard had just  replaced my Context variable with the Contextutil member from the ServicedComponent class it would have ran!

That code below:

 

Imports System.EnterpriseServices

<System.Runtime.InteropServices.ProgId("Comclass_NET.Comclass"), System.EnterpriseServices.Transaction(TransactionOption.Supported)> Public Class Comclass

      Inherits System.EnterpriseServices.ServicedComponent

      Public Function send_promo(ByRef str_param As String, ByRef COM As String) As String

            Dim Rs1 As New ADODB.Recordset

            Rs1.Open("select * from sysobjects", "Provider=SQLOLEDB.1;Data Source=chass;uID=xxx;pwd=sa;Initial Catalog=NorthWind")

        'Dim context As System.EnterpriseServices.ContextUtil ‘not needed now

            'UPGRADE_ISSUE: COMSVCSLib.AppServer  .GetObjectContext was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/redir/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'

        'context = GetObjectContext

            If COM = "Y" Then

            ContextUtil.SetComplete()

            Else

            ContextUtil.SetAbort()

            End If

            'UPGRADE_NOTE: Object Rs1 may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/redir/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'

        Rs1 = Nothing

        Return ""

      End Function

 

But I would have upgraded the VB 6.0 code to use the ServiceConfig Class and not messed around with inheriting from ServicedComponent, needing the SNK key, creating the COM+ application and and being much simpler that “upgrade”/rewrite below.

 

Imports System.EnterpriseServices

<System.Runtime.InteropServices.ProgId("Comclass_NET.Comclass"), System.EnterpriseServices.Transaction(TransactionOption.Supported)> Public Class Comclass

Public Function send_promo(ByRef str_param As String, ByRef COM As String) As String

        Dim conf As New System.EnterpriseServices.ServiceConfig()

        conf.Transaction = TransactionOption.Supported

        ServiceDomain.Enter(conf)

        Dim Rs1 As New ADODB.Recordset

        Rs1.Open("select * from sysobjects", "Provider=SQLOLEDB.1;Data Source=chass;uID=xxx;pwd=sa;Initial Catalog=NorthWind")

        If COM = "Y" Then

            ContextUtil.SetComplete()

        Else

            ContextUtil.SetAbort()

        End If

        'Rs1 = Nothing

        Return "text"

    End Function

 

 Hope this helps Somebody

Chuck