Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 2000/VB6/Oracle 8.1 and Object Creation under MTS

Status
Not open for further replies.

markag

Programmer
May 10, 2003
3
0
0
US
Hi All,
trying to get a firm grip on MTS object creation techniques and the good and bad ways to do it. I've read "Professional VB6 MTS Programming" by Bortniker and read tons online. The Bortniker book is out of date as I am using Windows 2000. I have read

"One of the big improvements in COM+ is the integration of COM and MTS. The two programming models have been unified. This eliminates the issue of calling to the MTS runtime versus calling to the SCM. This means that a call to the CreateObject function under Windows 2000 is the same as a call to CreateInstance. As long as a component is configured properly, the new object will always be loaded into the activity of its creator."

from
It is my understanding now that I should be instancing my MTS objects from other MTS objects, which reside in the same DLL, like this under Windows 2000/VB 6. For Example:

MyDll has 2 classes: MyRoot and MyOther. MyRoot is the class where my transaction originates from. Both classes are MultiUse and Requires Transaction. MyOther is the class I need to instantiate from within MyRoot.

From within MyDll.MyRoot Class:

Public Function Foo() As Boolean

' Reference to MTS Object Context
Dim ctxObject As ObjectContext
Set ctxObject = GetObjectContext()

Dim MyMTSObj As MyDll.MyOther
' Instantiate MyOther class within same activity
' is done this way according to docs to maintain
' transactional integrity within MTS.
Set MyMTSObj = CreateObject("MyDll.MyOther")

' I used to do it this way but I'm told this
' is *bad* under MTS
' Set MyMTSObj = New MyDll.MyOther

' Do Some Work with MyMTSObj
blnRtn = MyMTSObj.DoSomething()
If blnRtn = False Then
' Something went wrong. Lets abort
ctxObject.SetAbort
Foo = False
Else
ctxObject.SetComplete
Foo = True
End If

End Function

this will instance MyMTSObj within the same activity as the root object.

I'd feel warm and fuzzy if an MTS guru out there validated this for me.

Also, *when* and *if* or *never* should I do this (assuming ctxObject is a reference to the ObjectContext):
Set ctxObject = Nothing

This was asked of me by an associate.

TIA,
Mark
 
key words "ctxObject is a reference"
thus
Set ctxObject = Nothing
does nothing to the actual ObjectContext
It just removes your local reference to it.

Its just like doing this

Dim rs1 as recordset
Dim rs2 as recordset

Set rs1 = new recordset
rs1.Open "Select * From Customers","...",
set rs2 = rs1
Set rs1 = nothing

rs2 is still valid

COM holds a counter, any time someone grabs a reference to an object a counter is incremented. When a reference is set to nothing (or another valid object) then behind the scenes .Release of the object is call and the counter is decremented by on. When the counter gets to 0 then the object will clean itself up.

the use of NEW ignores the transactional setting of a Component Services/MTS object. It automatically includes the object in the current transaction. This is especially bad in situations where you are reading data because write locks are placed on that data until the transaction is finished.

So use CreateObject() or GetObjectContext.CreateInstance() for MTS objects. If your object is PRIVATE then you can use NEW as it doesn't have a transactional setting itself.

Just not that as normal using CreateObject() or GetObjectContext.CreateInstance() will not let you use Friend Methods.
 
"The use of NEW ignores the transactional setting of a Component Services/MTS object. It automatically includes the object in the current transaction. This is especially bad in situations where you are reading data because write locks are placed on that data until the transaction is finished."

Is this true? Does it matter which data provider you are using (SQL Server vs. Oracle)? I'm using Oracle 8.1.7. This then means that readers will block writers during an entire transaction? If that is true, would disconnected recordsets make a difference?

 
I've tried it here under 8.1.7 and SQL. Same behaivor on both. Its like doing a SELECT .... FOR UPDATE.
Disconnected recordset, IMHO, should be used in 90% of cases anyway. What you might want to do is have a class that has a transaction of NoTransaction to do your reads then make sure you don't use the NEW keyword to instanciate them.

err i just tested it agian....and i'm getting weird results. I have some sessions picking up dirty read others not. Now I'm getting confused.

What originally spawed me testing this is people on the Oracle board saying they where seeing write locks being put in on stored procedures that where read only. I was certian I tested this both in SQLServer and Oracle and got the same results (another guy here confirms that we did that) but when I run my tests now it is not happening.

So I think we should get some more input and I need to do more testing to see the behaivor...I'm also not sure what oracle settings could effect this so for all I know they (admin guys) may have done something to Oracle that causes this change.
 
Good info, and I will test it as well.

Thanks.
 
Sorry but I've been infected with some kind of flu (no its not SARS) and I honestly have a hard time remembering anything right now. I might be confusing things more then helping.
 
Hi
I am using MTS Ver2
Oracle 8
When I deploy m component in MTS I am getting Error.
When I am not deploying in MTS then it works properly.
Is thete any thing to be done to make MTS compatable to Oracle.I am using Microsoft ODBC Driver for Oracle.
Vsanas
 
did u install mts services for oracle???? also there is a sql script u have to run for table creation which is required for mts.this is available on oracle site .use the oracle search engine to search for this info
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top