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!

MTS not working for 3 tier arch

Status
Not open for further replies.

Mar28

Programmer
Jul 17, 2001
3
0
0
ID
Hi,

1.Our application involves a 3 tier architecture .Could u kindly send us a sample code for 3 tier architecture using VB.The SetComplete and the SetAbort functionality is not working for us as intended.The state of the objectcontext object is lost across the DLL boundaries so please tell us how to come over this problem.

Ex.
-------------------------------------------------------
This is the Form level EXE, which references business layer DLL(Test).
(Test --- ProjectName ; busTesting --- ClassName)

--------------------------------------------------------
Public sub subCheck()

Dim recValues as adodb.recordset
Dim objbusTesting as new Test1.busTesting
Dim intProjectid as integer

set recValues = objbusTesting.funGetValues(intprojectid)

End sub
------------------------------------------------------
This is the Business layer DLL which references the data layer DLL
--------------------------------------------------------

Public function funGetValues(byval intProjectid as integer) as adodb.recordset

On error GoTo errorhandler

Dim intProjectid as integer
Dim recFields as adodb.recordset
Dim objcon as Mtxas.objectcontext
set objcon = Getobjectcontext()

Dim objtboTesting as Test2.tboTesting
set objtboTesting = objcon.createinstance("Test2.tboTesting")

Set recFields = objtboTesting.funGetRecords(intProjectid)

set funGetValues = recFields

objcon.SetComplete
set recFields = nothing
set objcon = nothing
Exit function

errorhandler:
objcon.SetAbort
End function
--------------------------------------------
This is the Data Layer DLL
--------------------------------------------

Public function funGetRecords(byval intprojectid as integer) as adodb.recordset

On error goto errorhandler

Dim conn as adodb.connection
Dim strsql as string
Dim recopen as adodb.recordset

strsql = "select * from Testing where projectid = " & intprojectid

recopen.cursortype= adopenkeyset
recopen.locktype = adlockoptimistic
recopen.open strsql
set funGetRecords = recopen

Getobjectcontext.setcomplete()
Exit function

Errorhandler:
Getobjectcontext.setAbort()
End function
-------------------------------------------------------
This is the Sample Code which we use,in this we reference the Microsoft Transaction Server Type Library.Do we need to reference something else also.I would like to hear soon from you.In this case if any error occurs we need to Set Abort the entire transaction but the problem here it is not holding the same objectContext instance everywhere .Everytime it begins a new transaction which we don't want.The MTS transaction property for the Business object is set to REQUIRES A NEW TRANSACTION and for the table object is SUPPORTS TRANSACTION.When we do a set abort in the business it sets abort only that particular transaction and according to MTS even if we commit the transaction the table object it temporarily commits it and the only commits in the database in the Business object which is the root of the transaction.This does not work for me.It commits in the database and when any error comes it does not rollback the entire data but only rollbacks that specific transaction or data.Please reply ASAP.

Thanks,
Jairam

 


I don't know where you specify the server in your code.

This following code would work.

Dim objClass As Object
Set objClass = CreateObject("BizLayer.Class1",Servername)
Set receivingval = objPersist.Functionname(Parameter)


Please make sure that Bizlayer is registered in the local machine.

Renga


 
PLEASE GO THRU THIS MODIFIED VERSION OF THE LAST PARAGRAPH AGAIN

This is the Sample Code which we use,in this we reference the Microsoft Transaction Server Type Library.Do we need to reference something else also.

In this case if any error occurs we need to Set Abort the entire transaction but the problem here it is not holding the same objectContext instance everywhere .
Everytime it begins a new transaction which we don't want.

The MTS transaction property for the Business object is set to REQUIRES A NEW TRANSACTION and for the table object is SUPPORTS TRANSACTION.When we do a set abort in the business it sets abort only that particular transaction.According to MTS even if we commit the transaction ,the table object temporarily commits it .Its the business object where the final commit is done as it is the root of the Transaction.This does not work for me.It commits the previous data in the database and when any error comes it does not rollback the entire data but only rollbacks that specific record .Please reply ASAP.

REPLY TO RENGA

Hi Renga,

Thanks for your valuble suggestions

The sample code might not be fully informative as it may not show everything like the connection to the server.Our concern is that the SET ABORT and SET COMPLETE Functionalities of MTS are not working properly for multiple table updates within a single transaction i.e Rollback does not happen for all the tables parallely.

Thanks,
Jairam
 
In your form you are doing:

[tt]Dim objbusTesting as new Test1.busTesting[/tt]

Using the "as new" is bad practice, as you lose control over when the object is actually created. If you decide to dispose of the object by setting it to nothing, and then later accidentally reference that variable again, a new object is created for you (with no error message and with it's member variables being in an undeterminate condition). It's better to do this:

[tt]Dim objbusTesting as Test1.busTesting
Set objbusTesting = new Test1.busTesting[/tt]

This way if you dispose of the object, and accidentally reference it later, you get an error message which you will see in testing.


In your business layer, are your classes implementing the ObjectContext interface? And has all initialization/termination code been moved there from Class_Initialize and Class_Terminate?


And in the data layer, you're calling SetComplete and SetAbort. I think you ought to be returning a simple Success/Failure indication to the business layer, and let the Business layer handle the object context for you. What may be happening is the data layer is calling SetComplete, and then the Business layer is also calling SetComplete, and COM+ is saying "Hey, he's already out of the transaction, what's he doing calling SetComplete?"

I'd set both your Business and Data Layers to "Requires Transaction" so that a new one will be created when the code hits the business layer, and the data layer will inheirit the transaction from the business layer.

Chip H.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top