Configuring COM+ Application Pooling Values
You can use the following instructions to configure COM+ application pooling values for your COM+ application.
Note
Library applications have the recycling and pooling properties of their host process.
Component Services Administrative Tool
To configure COM+ application pooling for a COM+ application, use the following steps:
In the console tree of the Component Services administrative tool, right-click the COM+ application you want to be pooled and then click Properties.
On the Pooling & Recycling tab, under Application Pooling, enter a value for Pool Size, depending on the number of instances of your application that you want to have running.
Click OK.
Visual Basic
The following function in Visual Basic demonstrates how you can set the COM+ application pooling value (represented by its ConcurrentApps property) for any COM+ server application that you choose. To use it from Visual Basic, add a reference to the COM+ Admin Type Library.
Function SetMyApplicationPooling( _
strApplicationName As String, _
lngPoolValue As Long _
) As Boolean ' Return False if any errors occur.
SetMyApplicationPooling = False ' Initialize the function.
On Error GoTo My_Error_Handler ' Initialize error handling.
Dim objCatalog As COMAdmin.COMAdminCatalog
Dim objAppCollection As COMAdmin.COMAdminCatalogCollection
Dim objApplication As COMAdmin.COMAdminCatalogObject
Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")
Set objAppCollection = objCatalog.GetCollection("Applications")
objAppCollection.Populate
For Each objApplication in objAppCollection
If objApplication.Name = strApplicationName Then
objApplication.Value("ConcurrentApps") = lngPoolValue
MsgBox strApplicationName & _
" pooling value set to " & lngPoolValue
Exit For
End If
Next
objAppCollection.SaveChanges
Set objApplication = Nothing
Set objAppCollection = Nothing
Set objCatalog = Nothing
SetMyApplicationPooling = True ' Successful end to procedure
Exit Function
My_Error_Handler: ' Replace with specific error handling.
MsgBox "Error # " & Err.Number & " (Hex: " & Hex(Err.Number) _
& ")" & vbNewLine & Err.Description
Set objApplication = Nothing
Set objAppCollection = Nothing
Set objCatalog = Nothing
End Function
To use the function, provide a string value for the COM+ server application name and an integer value for the desired application pooling setting. The following Visual Basic code shows how to set the application pooling value to 15 for the application named "MyApplication":
Sub Main()
If Not SetMyApplicationPooling("MyApplication", 15) Then
MsgBox "SetMyApplicationPooling failed."
End If
End Sub
C/C++
The following function in C++ demonstrates how you can set the COM+ application pooling value (represented by its ConcurrentApps property) for any COM+ server application that you choose. The ErrorDescription method is described at Interpreting Error Codes.
#include <windows.h>
#include <stdio.h>
#import "C:\WINDOWS\system32\Com\ComAdmin.dll"
#include "ComAdmin.h"
#include "StrSafe.h" // For the StringCchLengthW function
BOOL SetMyApplicationPooling (OLECHAR* szMyApp, LONG lPool) {
IUnknown * pUnknown = NULL;
ICOMAdminCatalog * pCatalog = NULL;
ICatalogCollection * pAppColl = NULL;
ICatalogObject * pApplication = NULL;
HRESULT hr = S_OK;
BSTR bstrMyApp = NULL;
unsigned int uMaxLen = 255; // Maximum length of szMyApp
LCID lLan = 1024;// Use the default language for comparing strings.
try {
// Test the input pool value.
if ((lPool < 1) || (lPool > 1048576)) throw(E_INVALIDARG);
// Test the input szMyApp to make sure it's OK to use.
hr = StringCchLengthW(szMyApp, uMaxLen, NULL);
if (FAILED (hr)) throw(hr);
// Convert szMyApp to a BSTR.
bstrMyApp = SysAllocString(szMyApp);
// Create a COMAdminCatalog object and get its IUnknown.
hr = CoCreateInstance(CLSID_COMAdminCatalog, NULL,
CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);
if (FAILED (hr)) throw(hr);
// Get the ICOMAdminCatalog interface.
hr = pUnknown->QueryInterface(IID_ICOMAdminCatalog,
(void**)&pCatalog);
if (FAILED (hr)) throw(hr);
// Get an interface to the Applications collection.
hr = pCatalog->GetCollection(L"Applications", (IDispatch**)&pAppColl);
if (FAILED (hr)) throw(hr);
// Populate all of the Applications collection.
hr = pAppColl->Populate();
if (FAILED (hr)) throw(hr);
// Get the number of applications in the collection.
LONG lCount = -1;
hr = pAppColl->get_Count(&lCount);
if (FAILED (hr)) throw(hr);
// Iterate through each application in the collection.
VARIANT varName;
VariantInit(&varName);
for (LONG lIdx = 0; lIdx < lCount; lIdx++) {
hr = pAppColl->get_Item(lIdx, (IDispatch**)&pApplication);
if (FAILED (hr)) throw(hr);
// Get the Name value of each application.
hr = pApplication->get_Name(&varName);
if (FAILED (hr)) throw(hr);
// Compare the application name to bstrMyApp.
hr = VarBstrCmp(varName.bstrVal, bstrMyApp, lLan, NULL);
if (FAILED (hr)) throw(hr);
if (VARCMP_EQ == hr) { // The strings are equal.
// Set the new pooling value.
VARIANT varPool;
VariantInit(&varPool);
varPool.vt = VT_I4; // Tell the VARIANT it's holding a LONG.
varPool.lVal = lPool;
hr = pApplication->put_Value(L"ConcurrentApps", varPool);
if (FAILED (hr)) throw(hr);
printf("%S pooling value set to %ld.\n", bstrMyApp, lPool);
break;
}
}
LONG lNum;
hr = pAppColl->SaveChanges(&lNum);
if (FAILED (hr)) throw(hr);
// Clean up.
SysFreeString(bstrMyApp);
pUnknown->Release();
pUnknown = NULL;
pApplication->Release();
pApplication = NULL;
pAppColl->Release();
pAppColl = NULL;
pCatalog->Release();
pCatalog = NULL;
return (TRUE);
} // Try
catch(HRESULT hr) { // Replace with specific error handling.
printf("Error # %#x: ", hr);
ErrorDescription(hr);
SysFreeString(bstrMyApp);
if (NULL != pUnknown) pUnknown>Release();
pUnknown = NULL;
if (NULL != pApplication) pApplication->Release();
pApplication = NULL;
if (NULL != pAppColl) pAppColl->Release();
pAppColl = NULL;
if (NULL != pCatalog) pCatalog->Release();
pCatalog = NULL;
return (FALSE);
}catch(...) {
printf("An unexpected exception occurred.\n");
throw;
}
} // SetMyApplicationPooling
To use the function, provide a string value for the COM+ server application name and an integer value for the desired application pooling setting. The following C++ code shows how to set the application pooling value to 15 for the application named "MyApplication":
#define _WIN32_DCOM // To use CoInitializeEx()
void main() {
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED (hr)) {
printf("CoInitializeEx failed: Error # %#x\n", hr);
exit(0); // Replace with specific error handling.
}
if (! SetMyApplicationPooling (L"MyApplication", 15))
printf("SetMyApplicationPooling failed.\n");
CoUninitialize();
}
Related topics