.NET distributed transaction example

xiaoxiao2021-03-06  54

Using system; // Reference System Namespace Using System.Data.OLDB; // Reference ADO.NET Name Space Using System.Data; // Reference Data Space Using System.Runtime.InterOpServices; // In order to call Guidusing System.EnterpriseServices; // Reference COM Mission Space Using System.Runtime.CompilerServices; // Runtime Compile Server Using System.Reflection; // Use some global attributes Using System.Data.sqlcl CLIT; [Assembly] ("Comlibly: ApplicationName) ] // Strong name file name and file properties. Sn.exe generated by usage sn -k clsStock.snk // [assembly: AssemblyKeyFileAttribute ( "clsStock.snk")] // [assembly: AssemblyKeyName ( "clsStock.snk")] [assembly: AssemblyKeyFileAttribute ( "../ / Hystock.snk")][assembly: assemblyKeyname ("..//// Clsstock.snk")] Namespace Comlibrary {[Transaction (TransactionOption.Required) public class dboperty: servicedcomponent {

Private SqlConnection myconnection; private sqlcommand mycommand;

///

///connect database /// /// Database config infomation /// Formatting: DataSource = ..; user ID = ..; password = ... /// /// public void connection = "Workstation id = yanlixin; packet size = 4096; user ID = sa; data source = /" YANLIXIN / / SCGL / "; P" "Ersist Security Info = true; Initial Catalog = SCGL; Password = SCGL"; // myconnection = new sqlconnection; myconnection.open ();

MyCommand = new sqlcommand (); mycommand.connection = myconnection;

///

/// Execute One Insert Statement and Insert One Record Into the Table /// /// Database config infomation /// Formatting: DataSource = .. User ID = ..; password = ... /// /// public int commandExcute (string commandstring) {

Int returnvalue = 0;

Mycommand.commandtext = commandstring; returnvalue = mycommand.executenonquery (); return returnction;

}

///

/// Commit the COM Transaction ///

Public void commit () {

Contextutil.setComplete ();

IF (MyConnection! = NULL) myconnection.close ();

}

///

/// roolback the COM Transaction ///

Public void abort () {

Contextutil.Setabort ();

IF (MyConnection! = NULL) myconnection.close ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-115076.html

New Post(0)