×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 http://www.microsoft.com/mind/0899/basics/basics0899.asp

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

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

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.

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

(OP)
"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?

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

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.

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

(OP)
Good info, and I will test it as well.

Thanks.

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

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.

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

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

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close