???? ID: 198891 - ????? ???????: 03 ?????? 2010 - ??????: 4.0

SQL ????? ????????? ?? ???? ??? DLL-?????? COM ???????? ?? ????? ?? ??? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

Microsoft SQL Server 6.5 ?? ????? ???????????? ?? ???????? ?? ?????? ???????? ???????????? ????????? ??? ?? ????? ??? ???????? ???? (COM) ?????????? ?? OLE ??????? ?? ?? ??? ?? ?????? ?? ????? ?? ??? ?????? ?????? ????? ??? ???????? ??? ??, DLL-?????? COM ???????? ?? ??? ??? ????????? ?????, ?? ?? COM ???????? ??? ???? ??? ???? SQL ????? ????????? ?????? ??? ????? ???, ????? ?? ?? ??? ????? ????? ?????? ??? ????? ?? ???? ??? ??? ??? ?? ???? ?????, SQL ????? ????????? ????? ?? ??? ???? COM ???????? ??? DLL ????? ?? ??? ??? ???? ???? ???? ?? ??? adhere ???? ????? ??? potential ?? COM ???????? ???? SQL ????? ????????? ?? ????? ??????, ???????? ???? ?? ??? ?? ??? ?????? ???????? ?? ???? ???

??? suspicion ???????? ?? COM ???????? ??? ?? ???? ?? ??? robustness SQL ????? ????????? ?? ??, ?? ?? SQL ????? ????????? ????? ?? ???? COM ???????? instantiate ???? ?? ??? ?? ???? ??? ??? ????? ?? ????? ???? ?? ??? ?? ????? ??????????? ?????? ??? ???????? ???? ?? (DCOM) ?? ???????? ?????? ??? "????? ??????????" ?? ???????? ?? ?????? ?? ?????? SQL ????? ????????? ????? ?? ???? ??? DLL-?????? COM ???????? ?? ????? ?? ??? ???? ???

??? DLL-?????? COM ???????? ?? ????? ????????? ??? ????? ?? ???? ?? ??? ?? ????????? remoting ??? ???? ??? Remoting ?? ???????? ?? ?? ???? ???? ???????? ????? SQL ????? ???????? ????? ?? ????? ?? ??? surrogate ????????? ???? ?? ????? ??????? ???????? ????? DCOM ???? ???????? ??????? ?????? (rpcss.exe) ?? ????? Dllhost.exe ?? ??? ??? DCOM ?????? ?????? ???? ????????? ????? ??? DLL ?? ??? ???? ?? ??? Dllhost.exe ????? ?? ????? ???? ??, ?? ???? ??? ???? ???????, SQL ????? ?? ?? ?????? ??? ?? ?? ???? ?? ??? ?????? ???? ??? ???????? ?? transparently ?????? ???? ?? ??? ????????/???? ????? ?? ????? ???? ??? ???????? ????? ?? ??????? ?? ???? ?????? ???????/???? ?????? concurrently. ?????? ??????? ?? ????? ?? ????? ???? ??, DCOM ???? ???????? ??????? (SCM) ???? ????? ?? ?? unloading Dllhost.exe ????? ??? COM ???????? instantiations ?? ??? ??? ?????? ??????? ?? ???? ?? ??? ???????? ???? ???? ??????

???? ??? ?? ????? ???? ?? ??? ?? ???? ?? ???, ?????? ???? ????? ??? ????? DCOM ???????? ??????? ?? ???? ?? ?? ?? Microsoft Windows NT 4.0 ?????? ??? 2 ?? ??? ???, Microsoft Windows 98 ?? Microsoft Windows 95 ?? ??? DCOM ??-?? ??????? ??? ????? ????? ?? ???? ???? ?? ???? ??? SQL ????? ????????? ????? ??? ????? ?? ??? ?? ?? ???? ?? DLL-?????? COM ???????? ?? ??? ?? ?? ?? ?????? ?? ???? ???? ?? ??? ??sp_OACreate?? ??????? ???????? ??????????

???? ???????

Information about the two basic methods that you can use to instantiate the COM object out of process follows.

COM client requests remoting of the object

By changing the way that you invoke the COM object, you can request that the object be created outside of the SQL Server address space.
  • If the COM object is loaded by using thesp_OACreateprocedure, by default it is loaded in process. However, there is an optional third parameter to this procedure that may you can use to indicate the context of where to create the object. If this parameter is not specified, the default setting of five (5) is used, which means to run the object either inside or outside of the process. You need to change the parameter to four (4), which indicates to DCOM that this component is to run as a local executable. Use syntax that is similar to the following example to explicitly inform DCOM to run the COM object "out of process" using thesp_OACreatestored procedure:
       DECLARE @object int
       DECLARE @hr int
       EXEC @hr = sp_OACreate 'SQLOLE.SQLServer', @object OUT, 4
    						
  • If the COM object is created within an extended stored procedure the third parameter ofCoCreateInstance??,CoCreateInstanceExcan be changed to CLSCTX_LOCAL_SERVER. This is shown in the following code sample usingCoCreateInstance:
       HRESULT hr = CoCreateInstance(CLSID_Test, NULL, CLSCTX_LOCAL_SERVER,
         IID_IUnknown, (void**)&piunknown);
    						

Modify registry to force remoting of the object

If you cannot modify the COM client to request that the object be created out of process, two different methods exist to force the object to be created out of process.
  • Use the OLE/COM Object viewer (Oleview.exe) that is shipped with Microsoft Visual C++ and locate the ProgID in the form of OLEComponent.Object underAll Objects. Select the COM object, and then from the????????????, ?? ??? ????CoCreateInstance Flags. Make sure that only CLSCTX_LOCAL_SERVER is selected. Next, under theImplementation, ??Inproc Servertabs selectUse Surrogate Processand leave the "Path to Custom Surrogate" blank, which allows the Dllhost.exe file to be loaded and the COM DLL brought within it's process space.

    If you do not have Microsoft Visual C++, the OLE/COM Object Viewer utility is also available for download from the following Microsoft Web site:
    http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en (http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en)
  • Use the following steps to manually update the registry.

    ???????:??? ?? ????????? ?????? ?? ?? ???? ???? ???? ?? ????? ?? ????????? ?? ??? ??? ?? ??????? ???? ???, ?? ?? ????? ?????? ??????? ?? ???? ??.. ?? ???????? ?? ??? ???? ???? ???????? ?????? ?? ???: ??????? ???? ??? ???? ??.. Microsoft ?? ?????? ???? ?? ???? ?? ?? ???????? ?? ?? ???? ???.. ????????? ?? ???? ????? ?? ??????? ????..
    1. Obtain the Class Identifier (CLSID) of the COM object. The CLSID is a 128-bit number and considered a Globally Unique Identifier (GUID) that is used to uniquely identify the component, module or file that contains this COM object. When creating COM objects using the OLE Automation stored procedures, the first parameter to the stored procedure is a programmatic identifier or the ProgID of the OLE object is used to derive the CLSID. This character string describes the class of the OLE object and has the following form:
            OLEComponent.Object
      								
      You can use the programmatic identifier to find the class identifier for a COM object.

      Open the Registry Editor (Regedit.exe) and under the HKEY_CLASSES_ROOT key use the??????method to locate a key with the name of your<olecomponent.object></olecomponent.object>. You will find it at other levels, but it should be located at the level directly below the HKEY_CLASSES_ROOT. After you locate the key, expand the folder for the key name and you should see a subkey named CLSID. Click that folder to see the values within that key. On the right-hand side of the screen is a title named "(Default)". The data for that key should be in the following form:
            {59F929A0-74D8-11D2-8CBC-08005A390B09}
      								
      Make a note of this value or copy it to Notepad. Include the brackets.
    2. Navigate under the HKEY_CLASSES_ROOT\CLSID key and find the subkey with this GUID number. After you highlight the HKEY_CLASSES_ROOT\CLSID key you can use the??????function in Registry Editor (under the??????menu) and paste the GUID into the??????????? ????? ?? ??????? ?? ??? ?? .. Make sure that you have found the proper interface by inspecting the InprocServer32 subkey below this key, which points to the location of your COM DLL file. If there is a TypeLib key, check this GUID value. This should be different than what you noted in step 1. Otherwise, you have the TypeLib GUID and not the GUID for the COM object. The ProgID subkey will have a value of 'OLEComponent.Object.1'. The one on the end is for this sample only and is used for versioning information.
    3. While under the GUID's InprocServer32 subkey, make sure that a ThreadingModel value exists and that it is set to either Both or Free to make sure the marshaling understands the threading model of the COM object to enable execution of COM out of SQL Server process space. If there is not a ThreadingModel value or it is set to Apartment, COM object instantiation may not be consistent.

      ???:If you add the ThreadingModel value make sure that you test your COM object before implementing.
    4. Highlight the GUID number/subkey under the HKEY_CLASSES_ROOT\CLSID key. ???????????? ??,???, ?? ???? ??? ?? ??? ???????????? ???. ?? ??????????column, type the following:
      AppID
    5. ??? ?????ENTERand then insert the class identifier or GUID number you noted from step 1 as the value. The GUID should be inside the curly brackets as in the following example:
       
            {59F929A0-74D8-11D2-8CBC-08005A390B09} 
      
      								
      The application identifier AppID is used by DCOM to associate the DLL with an executable file.
    6. Add a new subkey under the HKEY_CLASSES_ROOT\AppID and set it's name to the same class identifier or GUID number with the brackets as inserted in the preceding step.
    7. Highlight the GUID name. ???????????? ??,???, and then select???????? ???. ?? ??????????column, type the following:
      DllSurrogate
      ???? ???????:column blank for this value. Because the data column is blank, this informs DCOM to run the default executable file, Dllhost.exe and load the COM object within it's process space.
    8. ????????? ?????? ?? ??? ????? ????? ????,????????? ????-????? ????, ?? ???? ????????. ??????????????? ????? ??? ????? ???? ????:
      DCOMCNFG
      ?????ENTER????? ?? ??? ??????????? COM ??????????? ???????? ????? ?? ??????? ?? ??? ?? .. ????? ??????????? ??????, ?? ????????? ???? ?? ???? ???????? ?? ?????? COM ?? ????? ????????? ??? ??? ?? ???? ??, ???? ??? ????, ?? ???? ??? ????? ???????? ????.
    9. ????????? ???? ?? SQL ????? ?? ??????? ?? ??? ?? ?? Microsoft Windows NT ?????????? ???? ??? "????? ????????" ?????? ?? ???????? ?? ??? ????????? ???????? ?? ??? ??? ????????? ???????? ???? ??? ?? ????????? ???????? ?? ??? ????? ?? ????? ???, ?? ????? ????????? ?? COM ???????? ??? ??? ???, ?? ?? ???? ??:
      OLE ??????? ?????? ???????
      HRESULT: 0X80040154
      ?????: ????????? ?? ??????? ODSOLE
      ?????: ???? ??????? ???? ???? ???

      OLE ??????? ?????? ???????
      HRESULT: 0X80070005
      ?????: ????????? ?? ??????? ODSOLE
      ?????: ?????? ????? ???

      OLE ??????? ?????? ???????
      HRESULT: 0X80080005
      ?????: ????????? ?? ??????? ODSOLE
      ?????: ????? ???????? ????
    10. ??????? ?? ??? ??? ?? Dllhost.exe ????? ?? ??? ??? ?? ??? ???? ????????? ????? ??? COM ???????? ?? ??? ?? ??? ??? ???? ??? ?????? ?? ?? Microsoft Windows NT ?????? ??? ?? Windows NT ???????? ??? ?? SQL ????? ?? ??? ??? ?? ????? ????????? ?????, ?? ????? ????????? ?? ????? Tlist.exe ????, ?????? ??? ??????????? ?? ???? ?????? ????????? ??????????, ?? ????????? ?????????? (PIDs) ?????? ??? Transact SQL ??? ???? ?????????sp_OACreate????? ?? ?? ?? ??? ????????? ???? ?? ???, ????? ????????? ?????? ???? ?? ????, ????? ????? ???? ?? ??? ???????? 20 ????? ?? ??? ????????? ???? ???? ??? ????? ??:
      WAITFOR DELAY '000:00:20'
      								
      ????????? ????? ?? ????? ??????? ???? ?? ??? ????? ????????? ?? Tlist.exe ????? ?? ?????? Dllhost.exe PID ??? ????? Tlist.exe ??? ?? ????? ?? ?? ???????? ?? ??? ??? PID ?? ??? ??? ?? DLL ??? Dllhost.exe ????????? ????? ??? ??? ?? ??? ?? ?????? ??? DLL-?????? COM ???????? ?? ??? ??? ?? ????????? ??? ?? ??? ???????? ???? ?????? ????????? ???? ??, ?? ??? Tlist.exe ?? ???: ????? reveals ?? Dllhost.exe ????????? ?? ???? ?? ??? ???

      ????? ????? ?????? ??? ADODB.Connection ???????? SQL ????? ????????? ????? ?? ???? ?? ???? ??? ?? ???????? Tlist.exe ?? ????? ?? ?? ?? ?? ?? Dllhost.exe ????????? ????? ??? COM ???????? ????? ??? ????? ??? ?? Msado15.dll, ?????? COM ???????? ??????? ??, ?? ??????? ??? ???
      C:\>tlist dllhost
       275 dllhost.exe
         CWD:     C:\NT40\system32\ 
         CmdLine: C:\NT40\System32\dllhost.exe {00000514-0000-0010-8000-00AA006D2EA4}
      -Embedding
         VirtualSize:    19180 KB   PeakVirtualSize:    19180 KB
         WorkingSetSize:  1780 KB   PeakWorkingSetSize:  1780 KB
         NumberOfThreads: 3
          278 Win32StartAddr:0x01001920 LastErr:0x00000000 State:Waiting
          215 Win32StartAddr:0x00001b5e LastErr:0x00000000 State:Waiting
          253 Win32StartAddr:0x00001b60 LastErr:0x000000cb State:Waiting
         4.0.1381.105 shp  0x01000000  dllhost.exe
         4.0.1381.130 shp  0x77f60000  ntdll.dll
         4.0.1381.121 shp  0x77dc0000  ADVAPI32.dll
         4.0.1381.133 shp  0x77f00000  KERNEL32.dll
         4.0.1381.133 shp  0x77e70000  USER32.dll
         4.0.1381.115 shp  0x77ed0000  GDI32.dll
         4.0.1381.131 shp  0x77e10000  RPCRT4.dll
         4.0.1381.117 shp  0x77b20000  ole32.dll
           6.0.8267.0 shp  0x78000000  MSVCRT.dll
                           0x1f310000  msado15.dll
          2.30.4265.1 shp  0x766f0000  OLEAUT32.dll
          4.0.1381.72 shp  0x77bf0000  rpcltc1.dll
      								
      SQL ????? ??????? ?? ??? Microsoft Windows 95 ?? Microsoft Windows 98 ????????????, "32-??? ??????? Loaded" ?? ?? ??? ????????? Microsoft ?????? ??????? ????? ??? 7.0 ???????? ??????? ????? ???? ?? ???? ???????? ?? ????? loading\unloading Dllhost.exe ????? ?? COM ???????? DLL ?? ?? ??????? ?? ????? ?? ????? ?? ???? ????? ?? ????? ??, ?? ??? ????? ????????????? ????? ????,????????????? ????? ????,????? ??????? ????-????? ????, ?? ???? ????????? ?????.
???:??????? ??????, ?? ???? Windows 95 ?? Windows 98 ?????? ???? ???? ?? DLLSurrogate ????????? ??????? ?? ??? ?? ?? ???? ?????? ??????? ?????? ???? COM DLL ??? ?? ??? ??? ?????, COM ???????? ?????? ??? ?? ??? ???????? ?????? (ROT) ????? ?? ?? ????/??? ??? ?????? ??????? ???????? ?????? ????? ?? ??? ?????? ??? ?? ?? ???? ??? ????? ?? ????? ?? ???? ??? ?? ?? SQL ????? ??? ???????? ?? ???? ?? suspected ??? COM ???????? ?? ??? ???? ??? ??? ???? ?? ???? ????????? ???? ?? ???????? ??? ?? ??????? thoroughly ?? ?????? ??????? ?? ????????? ???? ?? ??? ????????? ?? ??? ??? SQL ????? ????????? ??? ?? ???? ????????? ?? ????? ?? ??? COM ???????? instantiating ??? ??????????? ???? ?????? ??? ??? ??, ??? COM ???????? ?????? ?? ???? ????? ??? ?? ?????? leak ?? ???? ???? ?? ???? ??? ??? ????? ?? ??? ??? ?????? ?????? ??? ?? ????? ??? ??????????? ???? ?? ???? thoroughly ???????? ????? Microsoft ???????? ???? ??? ???? remoting COM ???????? ???? ?? ?????? ????? ???? ?? ???? ??? ?? ?? ?????? ??:
197426  (http://support.microsoft.com/kb/197426/ ) FIX: ????? ????? ?? ??????????? ?? ??? ADO ?????????? ??? ?? ??? ??
???:Microsoft SQL Server 6.5, ???????? ??? ??, ??? ????? Apartment (STA) ???? ?? ??? operates ?? ?????? ?? ??? ????? ?? COM ???????? ?? ???? ??????? ??? ?? ???? ??? ?? ????? ??? OLE ???????? SQL ????? ????????? ??? ?? ?? ?? COM ???????? ?? ????? ?? ???? ??? ??????? ??????? ?? ???????? ?? ??????? ?? ????????? ???? ?? ??? ????? ???? ??? ?? ?? internally ?? ??????? SQL ?????, ??????? ???????? persistence COM ???????? ?? instantiations ?? ??? ????????? ?? ???? ?? ?????

??????

SQL Server 6.5 COM ???????? ???? ?? ???? ??? ???? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
194661  (http://support.microsoft.com/kb/194661/ ) SQL ????? COM ???????? ???? persistence
???? ?? ????? ?? ???? ??? ???? ??????? ?? ??? Sp_OA ???????? ????????? ?? ???? ??, Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
180780  (http://support.microsoft.com/kb/180780/ ) Sp_OA ???????????? ????????? SQL ????? ?? ???? ???? ??
DLL Surrogates; ??? DLL-?????? COM ???????? ???? ?? ???? ??? ???? ??????? ?? ??? ????? ????? ??? ?? ???????:

Eddon, Guy; Eddon Henry,?????? ?????? ??? (Mps)?Microsoft ?????, 1998, (ISBN 1-57231-849-X), ?????? ??: ' DLL Surrogates ?? ???????? ????? ???

????? ???, Don,?????? COM. Addison Wesley Pub. Co., (0-201-63446-5 ISBN) ?????? ??: '?????????' Grimes, Richard,????????? DCOM ????????????. Wrox ????? Inc. (ISBN 1-861000-60-X), ??? ??????: '?????? ??? ???????? ????' DCOM ??-?? Windows 95 ?? ??? SQL Server 7.0 ?????? ?? ??? shipped ?? ?? ????? ??? Dcom95.exe ??? ?? Dcom95.exe ????? ??? ???? ?? ??????? ?? ???? ???:
HTTP://www.Microsoft.com/COM (http://www.microsoft.com/com)

???? ???? ???? ??:
  • Microsoft SQL Server 6.5 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup Edition
??????: 
kbinfo kbmt KB198891 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:198891  (http://support.microsoft.com/kb/198891/en-us/ )