C#transactions v SQL事务 [英] C# transactions v SQL transactions

查看:66
本文介绍了C#transactions v SQL事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用C#交易并且没有问题

他们。使用try catch块我可以捕获基本上所有可能的错误

并回滚所有必要的数据。


过去几天我一直试图转换这些代码中有一些是用于
的SQL Server存储过程,但它似乎缺少很多好处,而且很多错误似乎都没有。被错误的陷阱(例如,如果我对不存在的行进行更新,

不会发生回滚并继续执行,如果是表格我试图

访问不存在然后sproc崩溃了。


有谁可以告诉我写交易的原因是什么? />
存储过程而不是你的.NET代码,因为似乎没有任何对我来说是好的。

任何帮助都是真的赞赏。

干杯,

迈克

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!

I''ve been using C# transactions for a while and had no problems with
them. Using try catch blocks I can trap basically all possible errors
and rollback all necessary data.

Over the last few days I''ve been trying to convert some of this code to
SQL Server stored procedures, but it seems to lack many of the benefits
of C# transactions - a lot of the errors don''t seem to be trapped by the
SQL error trapping (e.g. if I do an update on a row that doesn''t exist,
no rollback occurs and execution continues, if a table I am trying to
access doesn''t exist then the sproc crashes).

Can anybody tell me what reasons there are for writing your transactions
in stored procedures rather than your .NET code, as there don''t seem to
be any to me.
Any assistance would be really appreciated.
Cheers,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

推荐答案

Mike P写道:
任何人都可以告诉我在存储过程中编写交易的原因是什么,而不是你的.NET代码,因为似乎对我没有任何意义。
Can anybody tell me what reasons there are for writing your transactions
in stored procedures rather than your .NET code, as there don''t seem to
be any to me.




我能想到...

更小更快的客户端应用程序

在不修改客户端应用程序的情况下更改程序

列表继续... :)



I can think of ...
Smaller and faster client applications
Changing of procedures whithout modifying client application
List goes on... :)

C#事务是什么意思?


你在谈论System.EnterpriseServices.ServicedComponent吗?或者


SqlConnection.BeginTransaction?


或其他什么?


问候


Richard Blewett - DevelopMentor
http:// staff.develop.com/richardb/weblog


nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/< e4 ** ************@TK2MSFTNGP14.phx.gbl>


我一直在使用C#交易并且没有问题

他们。使用try catch块我可以捕获基本上所有可能的错误

并回滚所有必要的数据。


过去几天我一直试图转换这些代码中有一些是用于
的SQL Server存储过程,但它似乎缺少很多好处,而且很多错误似乎都没有。被错误的陷阱(例如,如果我对不存在的行进行更新,

不会发生回滚并继续执行,如果是表格我试图

访问不存在然后sproc崩溃了。


有谁可以告诉我写交易的原因是什么? />
存储过程而不是你的.NET代码,因为似乎没有任何对我来说是好的。

任何帮助都是真的赞赏。

干杯,

迈克

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!


---

收到的邮件经过无病毒认证。

由AVG反病毒系统检查( http://www.grisoft.com)

版本:6.0.766 /病毒库:513 - 发布日期:17/09/2004


[microsoft.public.dotnet.languages.csharp]
What do you mean by a C# transaction?

Are you talking about System.EnterpriseServices.ServicedComponent? or

SqlConnection.BeginTransaction?

or something else?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<e4**************@TK2MSFTNGP14.phx.gbl>

I''ve been using C# transactions for a while and had no problems with
them. Using try catch blocks I can trap basically all possible errors
and rollback all necessary data.

Over the last few days I''ve been trying to convert some of this code to
SQL Server stored procedures, but it seems to lack many of the benefits
of C# transactions - a lot of the errors don''t seem to be trapped by the
SQL error trapping (e.g. if I do an update on a row that doesn''t exist,
no rollback occurs and execution continues, if a table I am trying to
access doesn''t exist then the sproc crashes).

Can anybody tell me what reasons there are for writing your transactions
in stored procedures rather than your .NET code, as there don''t seem to
be any to me.
Any assistance would be really appreciated.
Cheers,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004

[microsoft.public.dotnet.languages.csharp]


Mike ,


就个人而言,我认为在你存储的

程序中管理交易状态是一个非常非常糟糕的主意。它限制了它们如何在其他地方使用

,并且在大多数情况下,更难维护(因为你有更多的b $ b和更多的sp'相互呼唤,试图保持交易状态是痛苦的。


我建议使用EnterpriseServices处理交易

状态。这有很多原因,最好的一个很容易

可维护性(你可以通过点击

开关打开和关闭交易,或改变他们的行为)。处理这个的另一个原因是

,因为它提供了最简单的Indigo翻译路径。


希望这会有所帮助。


-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Mike P" < mr*@telcoelectronics.co.uk>在消息中写道

新闻:e4 ************** @ TK2MSFTNGP14.phx.gbl ...
Mike,

Personally, I think that managing transaction state in your stored
procedures is a very, very bad idea. It limits how they can be used
elsewhere, and for the most part, are harder to maintain (as you have more
and more sp''s calling each other, trying to maintain transaction state is a
pain).

I would recommend using EnterpriseServices for handling transaction
state. There are a number of reasons for this, the best one being easy
maintainability (you can turn transactions on and off with the flick of a
switch, or change their behavior). Another reason to handle this would be
because it offers the easiest translation path to Indigo.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:e4**************@TK2MSFTNGP14.phx.gbl...
我去过使用C#事务一段时间并且没有问题。使用try catch块我可以捕获基本上所有可能的错误
并回滚所有必要的数据。

过去几天我一直试图将一些代码转换为
SQL Server存储过程,但似乎缺少C#事务的许多好处 - 很多错误似乎都没有被SQL错误捕获困住(例如,如果我做的话)对不存在的行进行更新,
不会发生回滚并继续执行,如果我正在尝试访问的表不存在,则sproc崩溃)。

任何人都可以告诉我在存储过程而不是.NET代码中编写事务的原因是什么,因为对我来说似乎没有任何理由。

任何帮助都会非常感激。

干杯,

麦克

***通过Developersdex发送 http://www.developersdex.com ***
I''ve been using C# transactions for a while and had no problems with
them. Using try catch blocks I can trap basically all possible errors
and rollback all necessary data.

Over the last few days I''ve been trying to convert some of this code to
SQL Server stored procedures, but it seems to lack many of the benefits
of C# transactions - a lot of the errors don''t seem to be trapped by the
SQL error trapping (e.g. if I do an update on a row that doesn''t exist,
no rollback occurs and execution continues, if a table I am trying to
access doesn''t exist then the sproc crashes).

Can anybody tell me what reasons there are for writing your transactions
in stored procedures rather than your .NET code, as there don''t seem to
be any to me.
Any assistance would be really appreciated.
Cheers,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



这篇关于C#transactions v SQL事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆