????? ??????? ????????? COM + ?? ???? Visual C#

?????? ????????? ?????? ?????????
???? ???????: 816141 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ????? ??????? + COM ????????? (????? ????????) ?? ??? Visual C#. ????? ?????? ?? ?????? ????? ???? ?????. ??? ?? ???? ???? ???????? ?? ?? ???? ??? ????? ????? ??? ???????? ???????. ?? ?????? ???????? ?? ??? ??? ??? ?????? ????? ???????? ???? ?? ?????? ??? ????? ???????? ????????.

???????

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

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

????? ????? ???????? ?????? ?????? System.EnterpriseServices ?? Microsoft .NET Framework. ?????? ??? COM + ????? ????? ????????? ???. ?????? ????? ???? ??????? ???????:
  1. ??? ????? Visual Studio .NET ?? Visual Studio 2005.
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
  3. ???? ??? Visual C# ?????? ??? ????? Project ?? ???? ??? ????? ?????? ??? ?????. ??? ??????? prjEnterprise.

    ?????? ?? Visual Studio 2005 ? ???? ??? Visual C# ??? ????? Project ?? ???? ??? ????? ?????? ??? ?????. ??? ??????? prjEnterprise.
  4. ?????????? ??? ????? Class1.
  5. ?? "?????? ??????" ???? ??? ?????? ?????? ??? ????? ??? ?? ???? ??? ????? ????.
  6. ???? ???? ?????? ????? ??????. ??? ??? ?????? ??? ????? ??????? .NET ???? ????? ??????? ??? System.EnterpriseServices.
  7. ???? ?? ???? System.EnterpriseServices ??? ???????? ???????. ???? ??? ?????.
  8. ?? ?????? ???????? ???????? ??????? ??? ??? ?????? ???? ?? ??? Class1.cs:
    using System.EnterpriseServices;
    using System.Data.SqlClient;
  9. ????? ??? ????? ???? clsES ??? ??? Class1.cs.
  10. ???????? "?????" COM + ??????? ????? ??????? (clsES) ??? ?? ??? ????? ServicedComponent ??? ???:
    public class clsES : ServicedComponent
  11. ??? ??????? ??? ????????? ?????? ????? ??? ????????? ????? ??? ???:
    [Transaction(TransactionOption.Required)]public class clsES : ServicedComponent
  12. ????? ????? ?? ??? clsES ?? ??? dbAccess ????? ????? ?????? ????? ??? ????. ???? ???????? ??????? ???? ???? ?????? ????? ???? ??????. ????? ?????? ????????? ???? ???? ??????? ???????? ??????? ???? ??????. ??? ??????? ?????? ?????? ?? ?????? ????? ???????? ?? ?????? ?????? ?????? ??? ???? ??? ??????? ??? ??? ??????:
    void dbAccess(int pID1,int onOrder, int pID2, int inStock)
  13. ?? ????? dbAccess ????? ???? ????? SQL Northwind ????? ???????? ?? ?? ???? ???????. ???? ?????? ????? ???????? ???????? ????? ???????? ???????:

    ?????? ???? ?? ????? ?????? ????? ??????? ??????? ???? ????? ??????? ????? SQL Server.
    SqlConnection Conn = new SqlConnection("user id=<username>;password=<strong password>;Initial Catalog=northwind;Data Source=2E124\\SQL;");
    				Conn.Open();
    
  14. ????? ???? ???? ?????? ?? ??????????? ???? ?? ???? ????? ?????? ????? ????????. ??? ?? ???? ??? ??????????? ?????? ???????. ????? ???? ?????? ????? ?? ?????? ????? ????????. ?? ????? ????? ??? ????? ?? ???????? ?????? ???? ???.
     try { 
    
  15. ????? ??????? ????? ??? ???? ????????. ?? ?????? ????? UnitsonOrder ????? onOrder ?????? ?? ???? ? ??? ?? ???? ?? ?????? ??????? ???????. ??????? ??? SQL ?????? ?????? ??? ??????? SQL:
    SqlCommand sqlCommand = new SqlCommand("UPDATE myProducts SET UnitsonOrder = " + onOrder + " WHERE productID = " + pID1, Conn);
    				sqlCommand.ExecuteNonQuery();
  16. ????? ????? ??? ??? ???? ????????. ????? ????? UnitsinStock ?? inStock ???? ?????? ?? ???? ? ??? ?? ???? ?? ?????? ??????? ?????? ???????. ??????? ??? SQL ?????? ?????? ??? ??????? SQL:
    sqlCommand.CommandText = "UPDATE myProducts SET UnitsinStock = " + inStock + " WHERE productID = " + pID2;
    				sqlCommand.ExecuteNonQuery();
    
  17. ??? ??? ????????? ??? ?? ?????? COM + ? ??? ??????? ?????. ??? ??????? ????? setComplete ??? contextUtil ?? ????? ????? System.EnterpriseServices ???????? ???????? (?? ??? ?????? ????? ??????) ?? ???? ??? ???? ????? ?? ???:
    ContextUtil.SetComplete();
  18. ????? ??????? ?????? ?????? Northwind:
    Conn.Close();
    }
  19. ??? ?? ?????? ?? ????????? ???? ???? ????? ????? ????? SQL ???? ???? ????? ???????? ???????:
    catch(Exception e){ 
  20. ??? ??????? ????? setAbort ??? contextUtil ?? ????? ????? System.EnterpriseServices ????? ???????? ???????. ??? ??? ??????? ????? ?????? ??? ??????? ?????? ?? ??? ?? ????? ??????? ??? ???? ????????. ?? ??? ??????? caught ?????? ???? ??? ??? ????????:
    ContextUtil.SetAbort();
    				throw e;
    }
  21. ???? ?????? ????? ??? ?? ???? ?????? ??? ??? ????. ????? ??? ??? ?? ?? ?????? ??????? ?? ????? ??????. ?????? ????? ???? ??????? ???????:
    1. ?? ???? ??????? ????? ?? "Visual Studio .NET" ? ???? snEnterprise.snk ??? ???? sn.exe ?????? ??? ?????. ????? ?? ????????? ??? ????? ????????? ??? ????? ???? ???? ????? .NET Framework SDK.
    2. ??? snEnterprise.snk ??? ???? ???????.
    3. ?? AssemblyInfo.vc, ??? ????? ?????? ?? ????????? ???????? ??? ?? ??? ??? ?????? ??? ???????:
      [assembly: AssemblyKeyFileAttribute("..\\..\\snEnterprise.snk")]		
    4. ??? ??? ?? ????? ???????.

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

?????? Remember to change the following connection string parameters to reflect the correct values for your SQL Server server.
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.Common;
using System.EnterpriseServices;
using System.Data.SqlClient;

namespace prjEnterprise
{
	
	[Transaction(TransactionOption.Required)]public class clsES:ServicedComponent
	{
		public SqlConnection Conn;

		public void dbAccess(int pID1, int onOrder, int pID2, int inStock)
		{
			try
			{			
				SqlConnection Conn = new SqlConnection("user id=<username>;password=<strong password>;Initial Catalog=northwind;Data Source=2E124\\SQL;");
				Conn.Open();
				
SqlCommand sqlCommand = new SqlCommand("UPDATE myProducts SET UnitsonOrder = " + onOrder + " WHERE productID = " + pID1, Conn);
				sqlCommand.ExecuteNonQuery();
				
				sqlCommand.CommandText = "UPDATE myProducts SET UnitsinStock = " + inStock + " WHERE productID = " + pID2;
				sqlCommand.ExecuteNonQuery();

				ContextUtil.SetComplete();
				Conn.Close();
			}
			catch(Exception e)
			{
				ContextUtil.SetAbort();
			
				throw e;
			}
			finally
			{

			}
		}
	}	
}

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

??????? ??? ???????? ???????? ????? ????? ???? ???? ?????? ??????? clsES. ?? ???? ????? ?????? ???? ? onorder ? instock ??? ????? ?????? ?????? ??????. ???? ?? ?????? ??????? ????? ??? onOrder ???? ???? ???? ??????? ????? inStock ????? ?? ???? ???? ??? ??? ?????? ?????? ??? ????? ?? ?????? "??????". ????? ?? ??? ?????? ????? ????? ????????.
  1. ?? Visual Studio .NET ?? Visual Studio 2005 ??? ??? ???? ?? ??????? ??? ?? ???? ??? ???????.
  2. ???? ??? Visual C# ?????? ??? ????? Project ?? ???? ??? ????? ???? ?????? ??? ?????.

    ?????? ?? Visual Studio 2005 ? ???? ??? Visual C# ??? ????? Project ?? ???? ??? ????? ???? ?????? ??? ?????.
  3. ?? ???? ???? ????? ? ???? testES. ???? ?? ????? ?????? ????? ??? ????.
  4. ???? ??? ????? ?????? ??? ??????? ??? ????.
  5. testES ??????? clsES ??? ?? ???? ?????? ????. ?? "?????? ??????" ???? ??? ?????? ?????? ??? "???????" ??? testES (???? ??? ???? ???????) ??? ?? ???? ??? ????? ????.
  6. ???? ???? ?????? ????? ??????. ??? ????? ??????? "????????" ? ???? ????? ??????? ??? prjEnterprise.
  7. ???? ???? ??? ??????? ??????. ???? ??? ????? ?????? ??? ?????? ??? ???????.
  8. ????? ???? ??? ??????? ??? ????? System.EnterpriseServices. ?? "?????? ??????" ???? ??? ?????? ?????? ??? ????? ??? ?? ???? ??? ????? ????.
  9. ???? ???? ?????? ????? ??????. ??? ??? ?????? ??? ????? ??????? .NET ???? ????? ??????? ??? System.EnterpriseServices.
  10. ???? ?? ???? System.EnterpriseServices ??? ???????? ???????. ???? ??? ?????.
  11. ???? ??? ?????? ?????? ??? ??????? ???? ?????? (testES) ? ?? ???? ??? ????? ?? Project ??? ???????
  12. ?? ???? ???????? ???????? ?????? ??????? ?? ???? ??????? ????? Class1:
    	prjEnterprise.clsES myTest = new prjEnterprise.clsES();
    
    				try 
    				{
    					myTest.dbAccess(1, 777, 2, 888);
    					Console.WriteLine("TRANSACTION ONE -- SUCCESS");
    
    					myTest.dbAccess(1, 5, 2, -20);
    					Console.WriteLine("TRANSACTION TWO -- SUCCESS");
    				}
    				catch (Exception e)
    				{
    					Console.WriteLine("TRANSACTION FAILURE");
    				}
  13. ???? F5 ?????? ????????? ???????? ????????.

    ???? ????????? ????? ??? dbAccess ?? ????????? ???????? ?? ?????? 7. ?????? 1 ? 2 ?????? ?? ?????? "??????". ??? ????? ????? onOrder ?? 1 ?????? 777 ? ? inStock ????? ?????? ??? ????? ?????? 2 ??? 888. ??? ???? ??? ???????? ????? ??????? ??????? ?? ???? ???????
    ???? ????- ????????


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

    ????? ???? ??????? ??? dbAccess ? ??? ???????? ???????. ???? ?????? "??????" ??? ??? ??? ??????? dbAccess. ????? ????? ?????? ?????? ??? ?????? ?? dbAccess ?? ????? ????? ????? ??????? ?? ???? ???????:
    ??? ?? ????????
  14. ??? ??????? ?????? "?????? Northwind" ???????? ????? ??????? SQL Server. ??? ??? ?????? 1 ??? onOrder ?????? 777. ??? ??? 2 ?????? instock ????? ?? 888. ????? ???? ??????? ??? ??? dbAccess (???? ???? ??? ?? ??? ??? ?????? ??????).

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

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

?????

?????? ??? ???? ?? ?????????? ?? ?????? ????? ????? Network (MSDN) ?????? Microsoft ???????:
COM + ?????: ??? .NET Enterprise Services ???? ??????? ????? ????? ????????? ???????
http://msdn.microsoft.com/msdnmag/issues/01/10/complus/default.aspx
?????? serviced
http://msdn2.microsoft.com/en-us/library/Aa289839(VS.71).aspx

???????

???? ???????: 816141 - ????? ??? ??????: 12/?? ??????/1428 - ??????: 4.3
????? ???
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
????? ??????: 
kbmt kbcomplusobj kbsqlprog kbsqlclient kbdatabase kbhowtomaster KB816141 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????816141

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

 

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