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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activating MTS in a component - is it working ?

Status
Not open for further replies.

towser

Programmer
Feb 19, 2001
29
GB
I've only recently began using components and have completed one that handles security for a web application. As the number of users will be large I've been told to run the component under MTS. A week later and several books digested I've slapped some code into the component, registered it in a package using MTS explorer and when I run the application watched the globe rotate.

My component has NO transactions I'm only interested in the object pooling thing, where old instances of objects are used.

Does this mean my component is running correctly under MTS ?

I find it difficult to understand exactly how I can test this is working, any suggestions ?

Is the below code correct ?

'''''''''''''''''''''''''''''''''''''''''''''''''''''''

mplements MTxAS.ObjectControl

Private mobjContext As MTxAS.ObjectContext

Private Sub Class_Initialize()
#If NOMTS Then
ObjectControl_Activate
#End If
End Sub

Private Sub Class_Terminate()
#If NOMTS Then
ObjectControl_Deactivate
#End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''

component code functions here

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub ObjectControl_Activate()
#If NOMTS Then
Set mobjErr = New OEError.CError
#Else
Set mobjContext = GetObjectContext

If Not mobjContext Is Nothing Then

'Initialise transaction as failed. Ensures no accidental commit
If mobjContext.IsInTransaction Then
mobjContext.DisableCommit
End If
End If
#End If
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = True
End Function

Private Sub ObjectControl_Deactivate()
Set mobjErr = Nothing
Set mobjContext = Nothing
End Sub



Apologies for all the questions.

Towser
 
OK, there's a big caveat to MTS object pooling under Visual Basic: It doesn't work.

It's because VB can only create objects which are apartment threaded, and for object pooling to work under MTS (and COM+), the component must be free-threaded. And unless you want to write under VB.NET, you're looking at using C++ for this.

(.NET components are free-threaded, but you'll have to install the .NET runtime on your server, which may not be allowed by your IT staff)

Chip H.
 
Thanks Chiph.

What does work in MTS using VB ?

Are you saying that if I want a component that handles my security to run under MTS I need to write it in C++ or use .NET ?

All I'm interested in is making the component more efficient by using MTS, so a new object isn't created for each instance of the component.
 
MTS is still good in VB for transactioning (which you don't care about) and reducing the amount of time it takes to instantiate objects.

The apartment-threaded limitation of VB (no ability to do object pooling) is not usually an issue unless you've got hundreds of objects being created each second (like we do at work). So if your scalability requirements are modest (only a few tens of objects created each second), MTS will still work for you.

You will still get the advantages of having your database connections pooled (ADO maintains connections for a few seconds after you close them when in a MTS/COM+ environment), so every time you open a new connection (and everything about the connection is identical), it will pull one from the pool, saving you the expensive time it takes to open a connection and validate the DB user. That's a big plus right there.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top