Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent for getobjectcontext() in visual studio 2012 vb.net?

I have a vb6 COM object that I am converting to VB.Net 2012

My sample code looks like below :

Dim ObjContext ,objx ,objy As Object

Dim Rs As ADODB.Recordset

Set ObjContext = GetObjectContext

Set objx =ObjContext.CreateInstance("abc.class1")

Set Objy = ObjContext.CreateInstance("abcde.class2")


Set Rs = objx.getvalue(query)

 If Rs.EOF And Rs.BOF Then

      ObjContext.SetAbort
        Set objx = Nothing
        Set ObjContext = Nothing
        Set Objy = Nothing

  End If

What is the equivalent of GetObjectContext() and createinstance() in VB 2012?

How can i remove this concept from .net?

like image 802
BlueBerry - Vignesh4303 Avatar asked Nov 01 '22 13:11

BlueBerry - Vignesh4303


2 Answers

Try this:
I think u want this

Dim ObjContext ,objx ,objy As Object

Dim Rs As ADODB.Recordset

Set ObjContext = GetObjectContext

Dim ObjContext As COMSVCSLib.ObjectContext

Dim objAppServer As New COMSVCSLib.AppServer

ObjContext = objAppServer.GetObjectContext()

Set objx =ObjContext.CreateInstance("abc.class1")

Set Objy = ObjContext.CreateInstance("abcde.class2")


Set Rs = objx.getvalue(query)

 If Rs.EOF And Rs.BOF Then

      ObjContext.SetAbort
        Set objx = Nothing
        Set ObjContext = Nothing
        Set Objy = Nothing

  End If
like image 102
Somnath Kharat Avatar answered Nov 15 '22 06:11

Somnath Kharat


ObjectContext.CreateInstance goes way (way) back to Microsoft Transaction Server (MTS). It seems that in COM+ it's no longer necessary to create objects via the object context. Under COM+, regular CreateObject() does the right thing.

I found this information here: http://blogs.msdn.com/b/deva/archive/2012/01/19/com-mts-custom-application-createobject-or-createinstance.aspx.

In case that blog should disappear, here are the contents verbatim:

Recently i was working with a developer customer, who created an Visual Basic/COM+ based solution (internally uses the Microsoft Messaging library). In general, he wants to know whether they should use CreateObject or CreateInstance? Whether both will have the same or different same effect in COM+?

In Microsoft Transaction Server (MTS), you must use ObjectContext.CreateInstance in your root object to create secondary objects for the transaction to flow. In COM+ this still works, but it is no longer necessary to do it. In COM+, CreateObject subsumes the functionality of ObjectContext.CreateInstance. The object created participates in the caller's activity. In COM+, you can use the standard CreateObject function in Microsoft Visual Basic to flow a transaction to secondary objects as appropriate. So, CreateObject and CreateInstance have the same effect in COM+.

like image 45
Thomas F. Abraham Avatar answered Nov 15 '22 05:11

Thomas F. Abraham