跨数据库分布式事务的处理
2008-06-19 13:50
316 查看
using System;
using System.Collections.Generic;
using System.Text;
using System.EnterpriseServices;
using System.Data.SqlClient;
namespace myCOM
{
[Transaction(TransactionOption.Required)]
public class MyComClass : ServicedComponent
{
public SqlConnection Conn;
public SqlConnection Conn1;
public void test(string updateStr)
{
try
{
string connection = string.Format("server = pwdpc; database = Northwind; uid = sa; pwd = ******;");
SqlConnection Conn = new SqlConnection(connection);
Conn.Open();
string connection1 = string.Format("server = pwdpc; database = pubs; uid = sa; pwd = ******;");
SqlConnection Conn1 = new SqlConnection(connection1);
Conn1.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
cmd.CommandType = System.Data.CommandType.Text;
string sqlSentence = string.Format("update dbo.Customers set CompanyName = '{0}' where CustomerID = 'ALFKI'", updateStr);
cmd.CommandText = sqlSentence;
cmd.ExecuteNonQuery();
//出异常
//int i = 0;
//int j = 1 / i;
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = Conn1;
cmd1.CommandType = System.Data.CommandType.Text;
string sqlSentence1 = string.Format("update dbo.authors set au_fname = '{0}' where au_lname = 'White'", updateStr);
cmd1.CommandText = sqlSentence1;
cmd1.ExecuteNonQuery();
ContextUtil.SetComplete();
Conn.Close();
Conn1.Close();
}
catch (Exception ex)
{
ContextUtil.SetAbort();
throw ex;
}
finally
{ }
}
}
}
using System.Collections.Generic;
using System.Text;
using System.EnterpriseServices;
using System.Data.SqlClient;
namespace myCOM
{
[Transaction(TransactionOption.Required)]
public class MyComClass : ServicedComponent
{
public SqlConnection Conn;
public SqlConnection Conn1;
public void test(string updateStr)
{
try
{
string connection = string.Format("server = pwdpc; database = Northwind; uid = sa; pwd = ******;");
SqlConnection Conn = new SqlConnection(connection);
Conn.Open();
string connection1 = string.Format("server = pwdpc; database = pubs; uid = sa; pwd = ******;");
SqlConnection Conn1 = new SqlConnection(connection1);
Conn1.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
cmd.CommandType = System.Data.CommandType.Text;
string sqlSentence = string.Format("update dbo.Customers set CompanyName = '{0}' where CustomerID = 'ALFKI'", updateStr);
cmd.CommandText = sqlSentence;
cmd.ExecuteNonQuery();
//出异常
//int i = 0;
//int j = 1 / i;
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = Conn1;
cmd1.CommandType = System.Data.CommandType.Text;
string sqlSentence1 = string.Format("update dbo.authors set au_fname = '{0}' where au_lname = 'White'", updateStr);
cmd1.CommandText = sqlSentence1;
cmd1.ExecuteNonQuery();
ContextUtil.SetComplete();
Conn.Close();
Conn1.Close();
}
catch (Exception ex)
{
ContextUtil.SetAbort();
throw ex;
}
finally
{ }
}
}
}
相关文章推荐
- c#使用Transactions类完成多个数据库的事务操作(分布式事务处理)
- C# 操作数据库分布式事务处理
- oracle分布式处理时报“ORA-02041: 客户数据库未开始一个事务处理”解决办法 - z
- 分布式跨数据库的事务处理解决方案jta
- 数据库 分布式系统的事务处理
- 也谈 .NET2.0 事务处理 TransactionScope 的使用:[在访问相同数据库时避免讨厌的分布式事务]
- 分布式系统中数据库的事务如何处理?
- SQL 和Oracle对数据库事务处理的差异性
- 软件编程走火入魔之:数据库事务处理入门(适合初学者阅读)
- 分布式事务处理两阶段提交实例2及注意
- MSSQL数据库事务日志已满处理
- android Sqlite数据库事务处理*.sql 语句集文件
- JD订单去重的问题:谈分布式事务处理中领域驱动设计的原则
- 详解数据库集群的分布式事务、两阶段提交协议、三阶提交协议
- 关于数据库操作及事务的处理
- 分布式事务处理:原理、不足
- 性能比较: 事务处理控件(构建分布式应用程序)
- Spring入门之通过注解 处理 数据库事务
- SQL Server跨数据库访问及分布式事务的使用及配置
- SQL Server跨数据库访问及分布式事务的使用及配置