Examples of transactional Components
A simple calculator is far from a heavy workload of business applications, so we now consider applications with an object pool suitable for COM + transactional components.
The most easily managed and configured component is the managed code component exported by ServicedComponent, as shown in the following C # example: using System; using System. reflection; using System. runtime. interopServices; using System. enterpriseServices; using System. data; using System. data. sqlClient; [assembly: ApplicationName ("SCTrans")] [assembly: ApplicationActivation (ActivationOption. server, SoapVRoot = "SCTrans")] [assembly: AssemblyKeyFile ("SCTrans. snk ")] namespace SCTrans {public interface ISCTrans {string CountUp (string Key);} [ObjectPooling (MinPoolSize = 0, MaxPoolSize = 25)] [JustInTimeActivation (true)] [ClassInterface (ClassInterfaceType. autoDual)] [TransactionAttribute (TransactionOption. requiresNew)] public class SCTransSQLNC: ServicedComponent, ISCTrans {[AutoComplete] public string CountUp (string Key) {_ command = new SqlCommand ("", _ connection); _ command. commandType = Comma NdType. text; _ command. connection. open (); _ command. commandText = "UPDATE CallCount WITH (ROWLOCK) SET CallCount = CallCount + 1 WHERE Machine = '" + Key + "'"; _ command. executeNonQuery (); _ command. connection. close (); _ numcballs ++; return (_ numcballs + "NC" + _ guid);} protected override bool CanBePooled () {return true ;} private int _ numcils = 0; private string _ guid = Guid. newGuid (). toString (); pr Ivate SqlConnection _ connection = new SqlConnection ("user id = MyUser; password = My! Password; database = SoapTest; server = MyServer "); private SqlCommand _ command ;}}