this topic is kind of big, but you need to use DTC (Distributed Transaction Coordinator), read some basics:transactional programming with .net
http://www.develop.com/summercamp/conferencedotnet/materials/X8.pdf
http://www.develop.com/summercamp/conferencedotnet/materials/X8.pdf
Distributed Transactions Overview
http://msdn.microsoft.com/library/en-us/cossdk/htm/pgdtc_dev_3lrn.asp?frame=true
我的代码如下:生成DLL
using System;
using System.IO;
using System.Data;
using System.Data.OleDb;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Reflection;namespace Canon.wwg.wwgB.batch
{ [Transaction(TransactionOption.Required)]
public class DBOperation:ServicedComponent
{ private OleDbConnection myConnection;
private OleDbCommand myCommand; /// <summary>
/// connect database
/// </summary>
/// <param name=”connection”>database config infomation
/// formatting : datasource=..;user id=..;password=...
/// </param>
/// <returns></returns>
public void Connect(string connection)
{
myConnection = new OleDbConnection( connection );
myConnection.Open(); myCommand = new OleDbCommand();
myCommand.Connection = myConnection;
return;
} /// <summary>
/// Execute one insert statement and insert one record into the table
/// </summary>
/// <param name=”connection”>database config infomation
/// formatting : datasource=..;user id=..;password=...
/// </param>
/// <returns></returns> public int CommandExcute(string commandstring)
{ int returnValue = 0; myCommand.CommandText = commandstring;
returnValue = myCommand.ExecuteNonQuery();
return returnValue; } /// <summary>
/// Commit the com+ transaction
/// </summary> public void Commit()
{ ContextUtil.SetComplete(); if(myConnection!=null)
myConnection.Close(); } /// <summary>
/// Roolback the com+ transaction
/// </summary> public void Abort()
{ ContextUtil.SetAbort(); if(myConnection!=null)
myConnection.Close(); } }
}
在主文件中调用即可,注意要添加一个using System.EnterpriseServices;
大侠们提供的资料还没时间去看:(好像很难似的)
这问题先呆着,过几天再来:)