×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

MTS not working for 3 tier arch

MTS not working for 3 tier arch

MTS not working for 3 tier arch

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

RE: MTS not working for 3 tier arch



 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


RE: MTS not working for 3 tier arch

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

RE: MTS not working for 3 tier arch

In your form you are doing:

Dim objbusTesting as new Test1.busTesting

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:

Dim objbusTesting as Test1.busTesting
Set objbusTesting = new Test1.busTesting


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.

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