Microsoft KB Archive/260075

= PRB: Server Stops Responding When You Call Microsoft Transaction Server Component Under Active Server Pages =

Article ID: 260075

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Internet Information Server 4.0
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q260075



SYMPTOMS
When you call a Microsoft Transaction Server (MTS) component from a non-Microsoft Transaction Server component that is
 * running under Microsoft Active Server Pages (ASP) -and-


 * written in Microsoft Visual Basic

then your server may stop responding to ASP requests when it is placed under stress.



CAUSE
This behavior can happen if the calling component creates the second component through the use of CreateObject, instead of through the object context's CreateInstance method.

A call to Server.CreateObject always creates an MTS thread with a context wrapper. Therefore, the first object is created on an MTS thread and ends up creating a second object, which is an MTS object. CreateInstance should be used when you create an MTS object from an object in Microsoft Transaction Server.

Another way to avoid this problem is to configure the calling component into an MTS server package so that it will start in a different process than if it were created in Inetinfo.exe's process space.



RESOLUTION
Because the calling component is running under ASP, it has access to all of the ASP properties and methods. Instead of creating the component using CreateObject, you can use the CreateInstance property of the ObjectContext object. For an example of how to accomplish this, see the example in the &quot;More Information&quot; section.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new ActiveX DLL project in Visual Basic. Rename the project from &quot;Project1&quot; to NotAnMTSComponent . Rename &quot;Class1&quot; to CNotAnMTSComponent .  Paste the following code into cNotAnMTSComponent: Option Explicit

Public Sub Test

Dim x As Object Set x = CreateObject(&quot;MyMTSComponent.cMTSComponent&quot;) x.DoSomething Set x = Nothing End Sub  From the Visual Basic File menu, select Add Project, and create a new ActiveX DLL.</li> Rename the project from &quot;Project1&quot; to MyMTSComponent .</li> Rename &quot;Class1&quot; to cMTSComponent .</li> Set the MTSTransactionMode of cMTSComponent to 2 - Requires Transaction.</li> From the Project menu, select References, and add a reference to Microsoft Transaction Server Type Library .</li>  Paste the following code into cMTSComponent: Option Explicit

Public Sub DoSomething

Dim oc As ObjectContext Dim x As Integer Dim strNothing As String Set oc = GetObjectContext 'Waste some time here For x = 1 To 1000 strNothing = strNothing + String(1000 * Rnd + 1, &quot; &quot;) Next x   oc.SetComplete Set oc = Nothing

End Sub </li> Compile both .dll files.</li> Use your MTS Explorer to create a new package, and then add MyMTSComponent.dll to the package.</li>  Create an ASP page named Test.asp. Paste the following code into it: <%@ LANGUAGE = VBScript %> <%    dim myObj set myObj = SErver.CreateObject(&quot;NotAnMTSComponent.cNotAnMTSComponent&quot;)

%>

Done! </li> Use the Internet Services Manager to create a new application. Make its path C:\Inetpub\Wwwroot\Test. (Modify the path as necessary to suit your Internet Information Services [IIS] setup.) Ensure that the application is running in a separate process. Name the application Test .</li> Put Test.asp into C:\Inetpub\Wwwroot\Test.</li> Use a Web application stress tool (for example, http://webtool.rte.microsoft.com/) to apply a load to your Web site. Your application should stop responding (&quot;hang&quot;).</li></ol>

To solve the problem, change the code in cNotAnMTSComponent to: Option Explicit

Public Sub Test

Dim x As Object Dim oc as ObjectContext

Set oc = GetObjectContext Set x = oc.CreateInstance(&quot;MyMTSComponent.cMTSComponent&quot;) x.DoSomething Set x = Nothing set oc = nothing End Sub

<div class="references_section">