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!

new user of MTS 1

Status
Not open for further replies.

grouping

Programmer
Apr 24, 2001
4
US
I am writing a VB dll,to be called from ASP. I would like to make use of MTS. I am slightly confused:

How is it different to create a regular vb DLL and install as a package in MTS

as opposed to

using the getobjectcontext() withhin the VB dll
and installing as MTS package..

MTS gurus??

Thanks in advance
NC..
 
There really isn't any difference between what you've described.

What you should do is write an Active-X DLL that in it's method calls, calls getobjectcontext() to get a reference to the context object. You then do your thing. At the end of the function you call either SetComplete or SetAbort. Then set the context variable to Nothing.

Here are some design tips to make things easier for you:

1) Open and close the database connection in each method. Do not open it in the class_init and leave it open until class_terminate -- you'll confuse MTS. MTS is very good at caching database connections, and doing it this way is faster than you might think.

2) Do not use the "As New" method of instantiating objects. The safest way is to always use CreateObject, even if the class you're instantiating is in your own project.

3) Have good error handling. Having an unhandled error will confuse MTS.

4) Have only one exit point to your function. Using "Exit Sub" or "Exit Function" all over the place leaves you open to forgetting to call the correct context method (SetComplete, SetAbort).

5) Don't use any global or module level variables.

6) If you have to maintain state for the user, do it via a cookie or via an entry in the database. Don't use the Session object.

7) Always set your object variables to Nothing before leaving the function.

Hope this gets you started.

Chip H.
 
thanks for the response Chip.

So if i use
server.createobject for all my connections and recordsets, and not use object context at all and still register my dll under a MTS application, is it helpful in any way..

ie. is it better than just writing a vb dll and not creating an app out of it in MTS??

your tips are very helpful too!!
thanks in advance..

 
Our GUI layer is very thin -- most of the time all it does is call server.createobject and pass it parameters (usually XML strings). We did this because writing/debuging ASP and javascript code in Interdev is much harder than debugging VB code in the VB IDE. So, we write a VB DLL that does all our business logic and run it under COM+. Our ASP code would then call into this DLL (and other DLLs) for everything.

One other thing, you don't actually need to get a reference to the object context if what you're doing doesn't require a transaction. If all you're doing is SELECTing records, no transaction is required. But if you INSERT, UPDATE, or DELETE records, it should be done inside a transaction. What we did is create a class in our DLL for our non-transactional needs, and another one for the transactional operations. The MTS property on the classes was set appropiately. For example:

Non-transactional class:
[tab]MTSTransactionMode = 0 - Not an MTS object
[tab]No references to object context

Transactional class:
[tab]MTSTransacitonMode = 2 - Requires Transaction
[tab]Gets reference to object context, calls SetComplete and SetAbort as appropiate

If we need to go get a record from inside the transactional class, we just instantiate a copy of the non-transactional class and call the correct "fetch" method. Since the non-transactional class doesn't know or care about transactions, and isn't doing anything that would require a transaction, everything is OK.


Hope this helps.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top