惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
N
News and Events Feed by Topic
雷峰网
雷峰网
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 三生石上(FineUI控件)
Schneier on Security
Schneier on Security
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 最新话题
V
V2EX
T
Threat Research - Cisco Blogs
人人都是产品经理
人人都是产品经理
C
Cisco Blogs
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
I
Intezer
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
月光博客
月光博客
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News | PayPal Newsroom
Cyberwarzone
Cyberwarzone
B
Blog
博客园 - 聂微东
P
Palo Alto Networks Blog
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog
Scott Helme
Scott Helme
Google DeepMind News
Google DeepMind News
Webroot Blog
Webroot Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
O
OpenAI News
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
A
Arctic Wolf

博客园 - 吴建明

请讨论这个数据库该如何设计? vs2005读写vs2008项目 一个计算程序执行时间的批处理 使用fckeditor一个怪问题。。。 如何在ashx里提取context.Request.Files? 一个nhibenate的hql问题! 请问这样一个特殊的文本编辑器该如何实现? 还是关于无法加载DLL(OCI.DLL)问题解决办法! How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载) 欢迎大家讨论一个关于界面显示的问题!! 用installshield打包的asp.net程序 欢迎参与讨论一个分布式数据同步的问题! WF的tips 请问一下:诸位遇到输入汉字时会重复输入 请交一个关于域的问题 保护站点子目录的文件 整理了一个带语法高亮显示,及到处html功能的richtextbox控件 我现在做了个web系统,要求允许windows域用户自动注册,有什么建议 关于登陆到域的用户,不需要显示登陆界面的问题(aspx)
另外一个实现事务提交、回滚的方法
吴建明 · 2006-04-05 · via 博客园 - 吴建明

我们实现一个数据库事务,目前常用的,要么是在存储过程里面写上,要么就在Ado.Net层次控制,其实还有一种在asp页面层次中实现。

步骤如下:
添加引用System.EnterpriseServices.dll
using System.EnterpriseServices;

随便建立一个按钮,在按钮中进行如下操作:
try
{
 work1();
 work2();
 ContextUtil.SetComplete();
}
catch(System.Exception except)
{
 ContextUtil.SetAbort();
 Response.Write(except.Message);
}

然后在页面中添加2个操作,模拟一下在逻辑层调用不同类中的操作的情况
private void work1()
  {
   SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
   SqlCommand cmd1=new SqlCommand("Insert Into trantest (id,test)values(1,'test')",conn);
   conn.Open();
   cmd1.ExecuteNonQuery();
   conn.Close();
  }

  private void work2()
  {
   SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
   SqlCommand cmd2=new SqlCommand("Insert Into trantest (id,test)values(2,'test')",conn);
   conn.Open();
   cmd2.ExecuteNonQuery();
   conn.Close();
  }

修改前台页面在<%Page后面添加 Transaction="Required" 即可