Microsoft KB Archive/258736

= FIX: A DLL that was created by using Visual FoxPro 6.0 and that is running under Microsoft Transaction Server is slow to release connections =

Article ID: 258736

Article Last Modified on 8/7/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q258736



SYMPTOMS
A dynamic-link library (DLL) created with Microsoft Visual FoxPro and running under Microsoft Transaction Server is slow to release connections. This behavior occurs when a DLL is running under Microsoft Transaction Server (MTS) or Microsoft COM+ with Transaction Support marked as either &quot;Required&quot; or &quot;Requires New.&quot;



CAUSE
Releasing a COM server launched from a DLL under MTS or COM+ with Transaction Support marked as either &quot;Required&quot; or &quot;Requires New,&quot; initiates a call to CoFreeUnusedLibraries. When CoFreeUnusedLibraries is called, COM+ calls the DllCanUnloadNow function in every COM DLL in the process. If that call returns TRUE, then COM unloads the DLL.



RESOLUTION
Using Visual FoxPro 6.0 with Microsoft Visual Studio 6.0 Service Pack 4 or later, add the following line of code to the Init method of the code used to create the multi-threaded DLL: =SYS(2339,0)



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section. This bug was corrected in the latest service pack for Visual Studio 6.0.

For additional information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

To download the latest Visual Studio service pack, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/vstudio/Aa718353.aspx



MORE INFORMATION
Visual Studio 6.0 Service Pack 4 and later for Visual FoxPro 6.0 include the SYS(2339) function call. This function call may be used in single-threaded or multi-threaded DLLs to toggle when COM servers are released. The syntax for using SYS(2339) is: SYS(2339,1) && Default setting CoFreeUnusedLibraries called after a COM server is released. SYS(2339,0) && CoFreeUnusedLibraries is not called after a COM server is released. Setting SYS(2339,0) can improve scalability.

Steps to reproduce the behavior
 Create project named SLOWDLL .  Create a program file named SLOWDLL.PRG using the following code:

Note The user,, must have permissions to perform these operations on the database. DEFINE CLASS MTDLLDemo AS SESSION OLEPUBLIC

PROCEDURE foot

oMTX = CREATEOBJ('MTXAS.APPSERVER.1') oContext = oMTX.GetObjectContext

loCommand = CREATEOBJ('ADODB.Command') loRecordSet = CREATEOBJ('ADODB.RecordSet') loConnection = CREATEOBJ('ADODB.Connection') loConnection.CursorLocation = 3

*!* Note Adjust the name of the server used in the next line lcConnectionStr = &quot;Driver=SQL SERVER;SERVER=MY_SERVER;DATABASE=PUBS;UID=UserName;PWD=StrongPassword&quot; lcCommandStr = [SELECT Authors.au_id, Authors.au_lname, Authors.au_fname ] + ; [FROM dbo.authors Authors]

loConnection.OPEN(lcConnectionStr) loCommand.ActiveConnection = loConnection loCommand.CommandText = lcCommandStr

IF loRecordSet.State = 1 loRecordSet.CLOSE ENDIF loRecordSet.OPEN(loCommand)

loRecordSet.ActiveConnection = NULL loCommand.ActiveConnection = NULL loCommand = NULL loConnection.CLOSE

lnStart = SECONDS loConnection = NULL &&problem here lnStop = SECONDS

oContext.SetComplete

RETURN STR((lnStop-lnStart),6,2)+&quot; seconds to disconnect&quot;

ENDPROC

ENDDEFINE  Build either a single-threaded or multi-threaded DLL. Open the Microsoft Transaction Server/COM+ Management Console and create a new COM+ package named SLOWDLL. Open the Components folder of the SLOWDLL package.</li> Right-click on the Components folder, select New from the pop-up menu, and then select Component.</li> In the COM Component Install Wizard, select Import component(s) that are already registered and add the SLOWDLL.MTDLLDemo component.</li> After adding the component, right-click on the component and select the Properties option from the pop-up menu.</li> Select the Transactions tab and then select either the &quot;Required&quot; or &quot;Requires New&quot; button.</li>  From the Visual FoxPro Command window, run the following code: OX=NEWOBJECT('SLOWDLL.MTDLLDemo') ? OX.FOOT RELEASE OX                 </li></ol>

Additional query words: sp4

Keywords: kbbug kbfix kbvs600sp4fix kbvs600sp5fix KB258736

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.