.net用DbTransaction实现跨数据库事务,求大神解释

tanlinbo 2011-11-29 09:49:38
在.net下用测试类Transaction实现跨市据库事物,
...全文
235 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanlinbo 2011-11-29
  • 打赏
  • 举报
回复
额,谢谢了,
阿非 2011-11-29
  • 打赏
  • 举报
回复
可以考虑用 TransactionScope,虽然还有一些问题。

但应该满足你的需求
tanlinbo 2011-11-29
  • 打赏
  • 举报
回复
.net用DbTransaction实现跨数据库事务
阿非 2011-11-29
  • 打赏
  • 举报
回复
解析什么
thinkingforever 2011-11-29
  • 打赏
  • 举报
回复
http://blog.csdn.net/thinkingforever/article/details/193814
个人曾经写过的数据访问接口,包含:MSSQL、Mysql、Oracle等数据库的公共处理接口。可以拿过来直接使用,放在手里好多年了。 IDatabase接口声明如下: namespace Simple.Database { /// /// IDatabase 接口 /// public interface IDatabase { DbConnection dbConn { get; set; } /// /// 创建 DbConnection 对象实例。 /// /// DbConnection 对象实例。 DbConnection CreateConnection(); /// /// 创建 DbCommand 对象实例。 /// /// DbCommand 对象实例。 DbCommand CreateCommand(); /// /// 创建 DbCommand 对象实例。 /// /// Sql 语句或存储过程名。 /// CommandType 参数。 /// DbCommand 对象实例。 DbCommand CreateCommand(string text, CommandType type); /// /// 创建 DbCommand 对象实例。 /// /// Sql 语句或存储过程名。 /// CommandType 参数。 /// 参数集合。 /// DbCommand 对象实例。 DbCommand CreateCommand(string text, CommandType type, IDataParameter[] paras); /// /// 创建 DbCommand 对象实例。 /// /// DbConnection 对象。 /// Sql 语句或存储过程名。 /// CommandType 参数。 /// 参数集合。 /// DbCommand 对象实例。 DbCommand CreateCommand(DbConnection conn, string text, CommandType type, IDataParameter[] paras); /// /// 创建 DbDataAdapter 对象实例。 /// /// DbDataAdapter 对象实例。 DbDataAdapter CreateDataAdapter(); /// /// 创建 DbParameter 对象实例。 /// /// DbParameter 对象实例。 DbParameter CreateParameter(); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数值。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, Object value); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数类型。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, DbType type); /// /// 创建 DbParameter 对象实例。 /// /// 参数名称。 /// 参数类型。 /// 数据的最大大小。 /// DbParameter 对象实例。 DbParameter CreateParameter(string name, DbType type, int size); /// /// 获取指定长度数据的 DataSet 对象。 /// /// 要读取的 Sql 语句。 /// 开始读取位置的索引。 /// 待读取记录集的长度。 /// DataSet 对象。 DataSet GetDataSet(string sql, int start, int length); /// /// 获取指定长度数据的 DataTable 对象。 /// /// 要读取的 Sql 语句。 /// 开始读取位置的索引。 /// 待读取记录集的长度。 /// DataTable 对象。 DataTable GetDataTable(string sql, int start, int length); /// /// 执行Insert、Update、Delete等操作,并返回受影响的记录数。 /// /// 要执行的 Sql 语句。 /// 受影响的记录数。 int GetEffect(string sql); /// /// 执行 Insert、Update、Delete 等操作,并返回受影响的记录数。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 的类型,即该命令是 Sql 语句,还是存储过程名等。 /// 受影响的记录数。 int GetEffect(string sql, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回受影响的记录数。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// 受影响的记录数。 int GetEffect(string text, CommandType type, IDataParameter[] paras); /// /// /// /// /// /// /// /// /// int GetEffect(DbConnection conn, string text, CommandType type, IDataParameter[] paras, DbTransaction DbTrans); /// /// /// /// /// List ExecuteTransaction(params string[] sqls); /// /// 执行 Select 语句,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句。 /// DataSet 对象。 DataSet GetDataSet(string sql); /// /// 执行 Select 语句或存储过程,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// DataSet 对象。 DataSet GetDataSet(string text, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回 DataSet 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// DataSet 对象。 DataSet GetDataSet(string text, CommandType type, IDataParameter[] paras); /// /// 执行 Select 语句,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句。 /// DataTable 对象。 DataTable GetDataTable(string sql); /// /// 执行 Select 语句或存储过程,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// DataTable 对象。 DataTable GetDataTable(string text, CommandType type); /// /// 执行带参数的 Sql 语句或存储过程,并返回 DataTable 对象。 /// /// 要执行的 Sql 语句或存储过程名等。 /// CommandType 参数类型,即该命令是 sql 语句,还是存储过程名等。 /// 参数集合。 /// DataTable 对象。 DataTable GetDataTable(string text, CommandType type, IDataParameter[] paras); /// /// 获取查询所返回的结果集中第一行第一列的值。 /// /// 要处理的 sql 语句(包含待查询的字段)。 /// 字段值。 object GetField(string sql); /// /// 获取查询所返回的结果集中第一行指定列的值。 /// /// 待查询的数据表名称。 /// 待获取字段的列名。 /// 字段值。 object GetField(string sql, string field); /// /// 获取查询所返回的结果集中第一行指定列集合的值。 /// /// 要处理的 sql 语句。 /// 待获取字段的列表。 /// 字段值集合。 object[] GetField(string sql, params string[] fields); } }

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧