不需要,com+中的事务可以跨数据源,ado .net中提供的事务只能在一个数据源中起作用。com+的事务比ado.net中的事务也更灵活。
解决方案 »
- 求解:winform做的程序怎么实现自动升级更新功能
- 一个关于tabcontrol控件的问题,急急急!!!
- 如何给VPN客户端加IP地址?高手请过来看看
- visual studio 2005 与 sql server 2008 数据库连接不上
- 问如何匹配字符串
- c#开发的三层架构,oracle第一次启动太慢
- 请问如何得到文件的编码方式
- 在C#中怎样截取组合键(ctrl+shift)?
- 请各位有经验的人士共同讨论一下B/S开发中,如何更好的区分服务器和客户端开发,让系统更加高效!
- 谁帮我解决这个问题,有高分相送
- 有谁真正用.NET环境做过MapXtreme 2004的项目?
- 请教 MessengerAPI 使用问题
的
public class Class1
{
public bool TranDemo()
{
SqlConnection conn = new SqlConnection("server = localhost;User id = sa; password =centaurus;database=Northwind");
conn.Open(); SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
SqlTransaction tran=conn.BeginTransaction();
cmd.Transaction=tran;
try
{
cmd.CommandText = "update Products set unitPrice = 100 where ProductID =1";
cmd.ExecuteNonQuery();
tran.Commit();
return true; }
catch (Exception e)
{
tran.Rollback();
return false;
} }
}
另一个:
public class Tran
{
public bool TranDemo()
{
SqlConnection conn = new SqlConnection("server = wfw;User id = sa; password =centaurus;database=Northwind");
conn.Open(); SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
try
{
Class1 c=new Class1();
c.TranDemo();
cmd.CommandText = "update Products set unitPrice = 105 where ProductID =1";
cmd.ExecuteNonQuery();
return true; }
catch (Exception e)
{
return false;
} }
}
我在Tran类中,调用了Class1中的TranDemo函数,那么我想保证Tran类中的TranDemo函数的完整
性,该怎样处理?
2、方法前必须加[AutoComplete]属性(或者手动设置提交方式)[Transaction(TransactionOption.Required)]
[GuidAttribute("64615930-342c-4183-9ca4-8ae1589ebc51")]
public class Tran : ServicedComponent
{
[AutoComplete]
public bool TranDemo()
{
SqlConnection conn = new SqlConnection("server = wfw;User id = sa; password =centaurus;database=Northwind");
conn.Open(); SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
try
{
Class1 c=new Class1();
c.TranDemo();
cmd.CommandText = "update Products set unitPrice = 105 where ProductID =1";
cmd.ExecuteNonQuery();
return true; }
catch (Exception e)
{
return false;
} }
}
在多层架构的程序开发中,Com+服务组件我该放到那一层
我的程序分为:
客户层,业务外观层,业务逻辑层,数据访问层,数据实体层
using System.EnterpriseServices;
using System.Runtime.InteropServices;更详细的内容,请参见这里:http://www.microsoft.com/china/MSDN/library/default.mspx
另外,数据访问层还需要数据库的事务吗?
Com+事务对性能到底影响有多大?