PDA

Click to See Complete Forum and Search --> : MTS programming


gmcbath
Jul 27th, 2000, 07:05 PM
Most MTS books have simplistic examples, and of all the sample sources I have looked at I cant find an answer to my question. Can someone please help?

Should I make a call to GetObjectContext() in every function in my DLL?

Obviously you are going to do that in your "main" methods, but does calling GetObjectContext() in every function (main and helper functions) make your code more efficient?

In the following example I've called GetObjectContext() in each function. Is that overkill or quality coding practice?


Function Sum(nNumber1, nNumber2) as Integer

'--- this is the main function a client would call
GetObjectContext()

'--- now call helper function to do the work
nAnswer = TotalThem(nNumber1, nNumber2)

Sum = nAnswer

End Function

Function TotalThem(nNumber1, nNumber2) as Integer

GetObjectContext()
TotalThem = nNumber1 + nNumber2

End Function

pavan_kumard
Jul 28th, 2000, 05:01 AM
Object context is a part of Microsoft transaction server library.
If you are working with VB then you give reference to the microsoft transaction server linbrary.After that usually you initialize the object context by using
Dim oc as objectcontext
then after that when you are using it you dont say
set oc=new objectcontext
as is the usual method
this is because you cant create a new objectcontext.An object context is used to commit or roll back a transaction.
an object context is created as soon as you add the first object to a package.The first object called the primary object which initiates the transaction which when added to the package creates the object context.The other objects which use the transaction created by the prime objects are called secondary objects.These objects use the transaction created by the primary object.Each component created and added to the package have a say on the result of the transaction.If all the components are completed successfully(ie all tasks )then the transaction is said to be success ful.If even one fails the transaction is rolled back.The object context has two methods called setComplete and setAbort.All the dlls created by you should be prograsmmed in such a way that they return either of these two methods .Set Abort or Set Complete.In your program when you are writing you should decide when you get the correct result.There you should say set complete.You should identify possible errors that may occur and there you say setABORT.tHIS IS THE USUAL PRACTICE.
tHAT IS WHY YOU HAVE TO USE OBJECTCONTEXT EVERY WHERE IN ALL YOUR DLLS,EITHER TO SET COMPLETE OR SET ABORT A TRANSACTION.
i HOPE THIS WILL SOLVE YOUR PROBLEM