????? ??????? ????????? COM + ?? ???? Visual Basic .NET

?????? ????????? ?????? ?????????
???? ???????: 315707 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ????? ??????? + COM (???? ?????) ????????? ?? ??? Visual Basic .NET. ????? ?????? ?? ?????? ????? ???????? ????? ?????. ???????? ??? ???? ???? ?? ??? ?????? ??????? ?? ???? ??? ????? ?????. ?? ?????? ???????? ?? ??? ??? ??? ?????? ????? ???????? ???? ??? ???????? ??? ????? ???????? ????????.

???????

??????? ??????? ??? ??????? ?????? ??? ? ?????? ? ?????? ???????? ?????? ? ???????? ? ????? ? ??? ??????:
  • ???? ??????? Microsoft Windows 2000 Server ????? SP-1
  • Microsoft ????? ??????? ?????? (IIS) ??????? 4.0 ?? ??????
  • ??????? 5.0 ?? 5.5 ?? 6.0 ?? Microsoft Internet Explorer
????? ??????? ????????:
  • ????? ???????? ????????? ???????
  • ?????? ?? COM + (????? ????????)

COM + ????? ?????????

????? ????? ????? System.EnterpriseServices ???? Microsoft .NET framework ??????? ?????? ?????? ????????. ?????? ??? ?? ?????? ??? COM + ????? ????????? ?????? ??? ?????? ??????? ???????:
  1. ???? Visual Studio .NET.
  2. ????? ????? ????? ??? ????? ???? prjEnterprise ?? Visual Basic .NET. ???? Visual Basic .NET ??? ??? ?????? Class1.
  3. ????? ???? ??? ??????? ??? ????? System.EnterpriseServices. ?? ???? "????????" ???? "? ???? ??? ?????? ?????? ??? ?????? ????? ?? ??? ????? ???? ?? ??????? ????????. ??? ????? ??????? .NET ? ?? ???????? ??? ???? ?????? ???? System.EnterpriseServices. ???? ????? ??????? ??? System.EnterpriseServices ???? ?? ???? System.EnterpriseServices ?? ???? "???????? ???????" ?? ???? ??? ?????.
  4. ?????? ????? ?????? ????????? ????? ????? System.EntpriseServices ?????? System.Data.SqlClient ???? ?? ??? ????? ??? ????? ??? ?????? ????? ??? ???? ??? ?? ????????? ???????? ???? ????. ??? ?? ???? ??? ???????? ??? ??? ?????? ???? ?? ??? ?????:
    	Imports System.EnterpriseServices
    Imports System.Data.SqlClient
  5. ???????? "?????" COM + ??????? ??? ????? clsES ? ??? ?? ??? ????? ServicedComponent:
    	Public Class clsES
    Inherits ServicedComponent
  6. ??? ??????? ??? ????????? ?????? ????? ??? ????????? ?????:
    <Transaction(TransactionOption.Required)> Public Class clsES
       	Inherits ServicedComponent
  7. ????? ????? ???? clsES ???? dbAccess ????? ????? ?????? ????? ??? ????. ???? ???????? ??????? ???? ???? "?" ??????? ????? ???? ??????. ???? ?????? ????????? ???? ???? "?" ??????? ???????? ??????? ???? ??????. ??? ??????? ?????? ?????? ?? ?????? ????? ???????? ?? ?????? ?????? ?????? ??? ???? ??? ??????? ??? ??? ??????:
    	Public Sub dbAccess (ByVal pid1 As Integer, _
    ByVal onOrder As Integer, _
          ByVal pid2 As Integer, ByVal inStock As Integer)
  8. ?? ????? dbAccess ????? ???? ????? SQL Northwind ????? ???????? ?? ?? ???? ???????. ?????? ????? ???? ???????? ????? ???????? ???:
    Dim Conn As New _
      SqlConnection("uid=sa;database=northwind;server=localhost")
    Conn.Open()
  9. ????? ???? ???? ?????? ?? ?????? ????? ???????? ???? ?? ????. ??? ?? ???? ?????? ??? ??????? ??? ????? ?? ????? ????????. ????? ???? ???? ?????? ????? ????? ? ?? ???? ????? ??? ????? ?? ??? ???? ?????? ????.
    		Try
  10. ????? ??????? ????? ??? ???? ????????. ?? ?????? ????? UnitsonOrder ????? onOrder ?????? ?? ???? ? ??? ?? ???? ?? ?????? ??????? ???????. ??? ??????? SQLcommand ?????? ??? ??????? SQL:
    	   Dim Cmd As SqlCommand
          Dim sqlString As String = _
               "update products set UnitsonOrder = " & onOrder _
               & " where productId = " & pid1         
          Cmd = New SqlCommand(sqlString, Conn)
          Cmd.ExecuteNonQuery()
  11. ????? ????? ??? ??? ???? ????????. ????? ????? UnitsinStock ???? inStock ?????? ?? ???? ? ??? ?? ???? ?? ?????? ??????? ?????? ???????. ??? ??????? SQLCommand ?????? ??? ??????? SQL:
          sqlString = _
    "update products set UnitsinStock = " _
    & inStock & " where productId = " & pid2
               
          Cmd.CommandText = sqlString
          Cmd.ExecuteNonQuery()
  12. ??? ??? ????????? ??? ?? ?????? COM + ? ??? ??????? ?????. ??????? ??????? setComplete ????? contextUtil ?? ????? ????? System.EnterpriseServices ????? ????????-?? ??? ?????? ????????? ?????--?? ???? ??? ???? ????? ?? ???:
          ContextUtil.SetComplete()
  13. ????? ??????? ?????? ?????? Northwind:
          Conn.Close()
  14. ??? ????? ???? ????? ????? ????? SQL ??? ?? ???? ?? ??? ? ???? ??? ????? ???????? ???????:
    	   Catch e As Exception
  15. ??? ??????? ????? setAbort ??? contextUtil ?? ????? ????? System.EnterpriseServices ????? ???????? ???????. ??? ??? ??????? ????? ?????? ??? ??????? ?????? ?? ??? ?? ????? ??????? ??? ???? ????????. ?? ??? ??????? caught ?????? ???? ??? ??? ????????:
          	ContextUtil.SetAbort()
    			Throw e
    		End Try
  16. ????? ???? ?????? ????? ??? ?? ???? ?????? ??? ??? ????. ???? ??????? ??????? ?????? ??? ???? ? ????? ??????? ?? ????? ??????:

    1. ???? ???? ????? Visual Studio .NET ???? ??? ???? ? ?? ???? ??? ??????? ? ???? ??? Microsoft Visual Studio .NET ?? ???? ??? ????? .NET Visual Studio.
    2. ?? ???? ???????? ???? snEnterprise.snk ??? ???? sn.exe ?????? ????? ?? ??????? ??? ??? ????.

      ????? ?? ????????? ??? ????? ????????? ??? ????? ???? ???? ????? .NET Framework SDK.
    3. ??? snEnterprise.snk ??? ???? ???????.
    4. ?? AssemblyInfo.vb, ??? ????? ?????? ?? ????????? ???????? ??? ?? ??? ?????? ?????? ??? ???????:
      <Assembly: AssemblyKeyFileAttribute("..\..\snEnterprise.snk")>
    5. ?? ???? ?? ????? ???????.

????? ??? ????????? ????????

Imports System.Data.SqlClient
Imports System.EnterpriseServices

<Transaction(TransactionOption.Required)> Public Class ClsES
    Inherits ServicedComponent

Public Sub dbAccess(ByVal pid1 As Integer, ByVal onOrder As Integer, _
      ByVal pid2 As Integer, ByVal inStock As Integer)

        Dim Conn As New _
          SqlConnection("uid=sa;database=northwind;server=localhost")
          Conn.Open()
        Try
          Dim Cmd As SqlCommand
          Dim sqlString As String = _
             "update products set UnitsonOrder = " & _
              onOrder & " where productId = " & pid1
          Cmd = New SqlCommand(sqlString, Conn)
          Cmd.ExecuteNonQuery()

          sqlString = _

         " update products set UnitsinStock = " & inStock & _
                " where productId = " & pid2
           Cmd.CommandText = sqlString
           Cmd.ExecuteNonQuery()

           ContextUtil.SetComplete()
           Conn.Close()
        
         Catch e As Exception
            ContextUtil.SetAbort()
		  Throw e
        End Try
    End Sub 
End Class

???? ?? ??? ????

??????? ??? ???????? ???????? ????? ????? ???? ???? ?????? clsES. ?? ???? ????? ?????? ???? ? onorder ? instock ??? ????? ?????? ?????? ??????. ???? ?? ?????? ??????? ????? ??? onOrder ???? ???? ???? ??????? ????? inStock ????? ?? ??? ???? ??? ??? ?????? ?????? ??? ????? ?? ?????? "??????". ???? ?? ??? ????? ?????? ?? ?????? ??? ?????.
  1. ????? ????? ???? ???? ???? ???? testES ??? ???? ????? ?? ???? ????? ???? ??? ??????? testES ?????? prjEnterprise. ?????? ????? ???? ???? ??? "????" ?? ????? "???" ??? ?? ??? Project.
  2. ???? ???? ???? ????? ????. ??? ?????? Visual Basic ?? ??????? ??? ????? ??? ?? ??? ???? ?????? ????????? ?? ???????. ?? ?????? ????? ???? ??? ??????? ???? testES ????? ?? ??? ???????. ???? ?? ????? ???? ????? ??? ???? ???? ???? ?? ???? ???? ??????. ???? ??? ????? ?????? ??? ??????? ??? ????.
  3. ??? testES ??????? clsES ??? ????? ????. ?? ???? ???? ???? ??? ?????? ?????? ??? ?????? ????? ????? ??? testES ??????? ???? ??? ???????. ??? ????? ????. ???? ???? ???? ????? ????.
  4. ??? ????? ??????? ?????? ??? ?? ???? ????? ??????? ??? prjEnterprise. ??? ?? ???? ???? ?? ???????? ??????? ?? ????? ?????? ?? ???? ??????. ???? ??? ????? ?????? ??? ?????? ??? ??? ???????.
  5. ???? ??? ?????? ?????? ??? ???? ?????? ???????? testES ???? ?? ????? ??? ??? ????? Project.
  6. ?? ??????? ????? ??? Windows. ?? ??????? ??????? ??? ????. ??? ???? ?????? ?????? ??????.
  7. ??? ????????? ?????? ???????? ??????? ?? "?????? ??????? ?????? ??????? 1" ??????? ?????? ??????? Sub ? End Sub. ??? ?? ???? ?????? ??????? ??? ???:
        Sub Main()
            Dim myTest As New prjEnterprise.clsES()
    
            Try
                myTest.dbAccess(1, 777, 2, 888)
                Debug.WriteLine("TRANSACTION ONE -- SUCCESS")
               
                myTest.dbAccess(1, 5, 2, -20)
                Debug.WriteLine("TRANSACTION TWO -- SUCCESS")
            
            Catch
                Debug.WriteLine("TRANSACTION FAILURE")
            End Try
        End Sub
  8. ???? F5 ?????? ????????? ???????? ????????.
  9. ???? ????????? ????? ??? dbAccess ?? ????????? ???????? ?? ?????? 7. ???? 1 "?" ???? 2 ?? ?????? "??????". ??? ????? ????? onOrder ?????? 1 777 ? ? inStock ????? ?????? ??? ????? ?????? 2 ??? 888. ??? ???? ??? ???????? ??? ??? ?????? ?????? ????? "???????? ONE - ????".

    ??? ??????? ??? ??? dbAccess. ????? ?? ??? ?? ?????? ??????? ??? dbAccess ??? ???????? ?? ??? ?????? ??? ????? ????????. ??? ????? ?? ?? ???? ?????? 1 ??? onOrder ????? ??? ????? ??? 5, ?? ???? ?? ???? ?????? 2 ????? ?? inStock ????? ????? ???-20. ????? ??? ????? ???? ????? ?????? ?????? inStock ??? ????? ?? ???? ???? ????? ?????.

    ????????? ??? ????????? ??? dbAccess ??? ? ??? ???? ??? ??? ??????? ???????. ???? ???????? ???? ??? ??? ??? ??????? dbAccess. ????? ????? ?????? ?????? ??? ?????? ?? dbAccess ??????? ?? ????? "???????? FAILURE" ???? ?? ???? ?? ?????? ??????.
??? ??????? ?????? "?????? Northwind" ???????? ????? ??????? SQL Server. ??? ??? ?????? 1 ??? onOrder ????? 777; ?????? 2? instock ????? ?? 888. ????????? ??? ??????? ?????? ??? dbAccess ?? ???? ???? ?? ??? ?????? ??? ??????.

??????? ??????? ????????

  • ???? ?? ???? ?? ????? ?????? ????? COM + ??? ??? ????.
  • ??? ?? ??? ??? ??? ?????? ????? + COM ?? ???? serviced ?????? ?? ????? ????? System.EnterpriseServices ????.
  • ????? ????? ? ?? ???? ?????? ??? ?? ??? ???????? ??? ?? ?? ?????. ????? ???? ??????? ????? ???? ??? ??? ????????. ?? ???????? ????? ???????? ???? ????? 1,200 ?????? ?? ????????? ??? ?????? ??????:
    <Transaction(TransactionOption.Required, timeout:=1200) >

?????

?????? ??? ???? ?? ?????????? ?? ?????? ????? ????? Network (MSDN) ?????? Microsoft ???????:
COM + ?????: ????? ??????? ??????? ??????? .NET Enterprise ????? ????? ??????? ???????
http://msdn.microsoft.com/msdnmag/issues/01/10/complus/

?????? serviced
http://msdn.microsoft.com/en-us/library/aa289839.aspx

???????

???? ???????: 315707 - ????? ??? ??????: 06/????/1426 - ??????: 3.2
????? ???
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
????? ??????: 
kbmt kbhowtomaster KB315707 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????315707

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com