DbProviderFactory和交易。 [英] DbProviderFactory and transactions.

查看:63
本文介绍了DbProviderFactory和交易。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用DbProviderFactory类从提供商那里获得
摘要,有没有办法使用交易?


如果没有,有没有办法管理通用/提供商中的并发性

独立模式?


我已经看到使用DataSet时(乐观锁定),如果更新

检测并发问题,可以通过

MessageBox或ASP页面或任何其他GUI方式通知用户。

我有2个或更多通过Web服务与DB同步的手持设备

我不希望手持设备由于并发而停止同步

问题:我希望WS能够处理问题,例如cycing,直到它成功更新数据库或类似的东西。


在这种情况下如何管理并发?

什么是最佳做法?

非常感谢,

Luigi。

Is there any way to use transactions if I use DbProviderFactory class to
abstract from the provider?

If not, is there any way to manage concurrency in a "universal"/provider
indipendent mode?

I''ve seen that when a DataSet is used (optimistic lock), if the update
detect concurrency problems, it is possible to inform the user with a
MessageBox or on the ASP page or in any other GUI way.

I''ve 2 or more handheld devices that sync with a DB through a Web Service
and I don''t want the handhelds to stop syncing because of a concurrency
problem: I''d like the WS to handle the problem for example cycing until it
succeeds updating the DB or something like that.

In such situations how can concurrency be managed?
What is the best practice?
Thanks a lot,
Luigi.

推荐答案

Luigi,


如果您使用的是DbProviderFactory抽象类,那么当您使用
调用CreateConnection时,您可以调用BeginTransaction得到一个

DbTransaction实例,你可以用它来管理一个交易。


就个人而言,我会在

System.Transactions命名空间,并将你的调用包装到DbProviderFactory

中。如果基础提供程序支持它(并且如果它与.NET 2.0中的DbProviderFactory一起工作,那么它将会运行,那么它将自动登记在

交易中,并且你赢了'不必亲自手动处理。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" BLUE" < bluewrote in message news:OS ************** @ TK2MSFTNGP02.phx.gbl ...
Luigi,

If you are using the DbProviderFactory abstract class, then when you
call CreateConnection, you can then call BeginTransaction to get a
DbTransaction instance which you can use to manage a transaction.

Personally, though, I would use the TransactionScope class in the
System.Transactions namespace, and wrap your calls to the DbProviderFactory
in that. If the underlying provider supports it (and it should if it works
with the DbProviderFactory in .NET 2.0) then it will auto enlist in the
transaction, and you won''t have to manually handle it yourself.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"BLUE" <bluewrote in message news:OS**************@TK2MSFTNGP02.phx.gbl...

有没有如果我使用DbProviderFactory类从提供者那里获得
摘要,那么使用事务的方式是什么?


如果没有,有没有办法在通用中管理并发性; / provider

独立模式?


我已经看到使用DataSet时(乐观锁定),如果更新

检测并发问题,可以通过

MessageBox或ASP页面或任何其他GUI方式通知用户。


我通过Web服务与数据库同步的2个或更多手持设备

我不希望手持设备因并发而停止同步

问题:我希望WS能够处理问题,例如cycing,直到它成功更新DB或类似的东西。


在这种情况下如何并发可以是管理ed?

什么是最佳做法?


非常感谢,

Luigi。
Is there any way to use transactions if I use DbProviderFactory class to
abstract from the provider?

If not, is there any way to manage concurrency in a "universal"/provider
indipendent mode?

I''ve seen that when a DataSet is used (optimistic lock), if the update
detect concurrency problems, it is possible to inform the user with a
MessageBox or on the ASP page or in any other GUI way.

I''ve 2 or more handheld devices that sync with a DB through a Web Service
and I don''t want the handhelds to stop syncing because of a concurrency
problem: I''d like the WS to handle the problem for example cycing until it
succeeds updating the DB or something like that.

In such situations how can concurrency be managed?
What is the best practice?
Thanks a lot,
Luigi.



但就个人而言,我会在
Personally, though, I would use the TransactionScope class in the

System.Transactions命名空间中使用TransactionScope类,并换行你打电话给那个

DbProviderFactory
System.Transactions namespace, and wrap your calls to the
DbProviderFactory in that



非常感谢你!

我没有'不知道它,但在5分钟内我看到它很容易使用和

强大。

我会使用交易所以如果有的话问题我可以回滚所有插页

并更新我已在事务范围内完成。


我想创建一个字符串并将其插入到只有在没有
存在的情况下才会记录数据库:如果它存在我想生成另一个字符串并重试,因此

on(这是多个用户插入时的情况进入我的桌子

,我需要检查主键i在插入之前是唯一的而不是等待

最终的例外)。

我可以循环直到插入顺利或有更好的方式(最好

练习)?

谢谢,

Luigi。

Thank you very very much!!!
I didn''t know about it but in 5 minutes I''ve seen it''s easy to use and
powerful.
I''ll use transactions so if there are problems I can roll back all inserts
and update I''ve done inside a transaction scope.

I want to create a string and insert it into a record of the DB only if not
present: if it is present I want to generate another string and retry and so
on (this is the scenario when multiple users are inserting into my tables
and I need to check primary key is unique before inserting it and not wait
the eventual exception).
Can I loop until an insertion goes well or there is a better way (best
practice)?
Thanks,
Luigi.


Luigi,

你是如何产生主键的?

冲突?

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" BLUE" < bluewrote in message news:O8 ************** @ TK2MSFTNGP03.phx.gbl ...
Luigi,

How is it that you are generating your primary key where you can get
conflicts?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"BLUE" <bluewrote in message news:O8**************@TK2MSFTNGP03.phx.gbl...

>不过,就个人而言,我会在
System.Transactions命名空间中使用TransactionScope类,并将你的调用包装在那个
>Personally, though, I would use the TransactionScope class in the
System.Transactions namespace, and wrap your calls to the
DbProviderFactory in that

<中的
DbProviderFactory中br />
非常感谢你!

我不知道它但在5分钟内我看到它很容易使用和

功能强大。


我会使用交易,所以如果有问题我可以回滚所有插页

并更新我''已在事务范围内完成。


我想创建一个字符串,只有当

不存在时才将其插入到DB的记录中:如果是现在我想生成另一个字符串并重试

等等(这是当多个用户插入我的

表并且我需要检查主键是唯一的情况在插入之前和
不等待最终的异常)。

我可以循环直到插入顺利或有更好的方法(最好

练习)?


谢谢,

Luigi。


Thank you very very much!!!
I didn''t know about it but in 5 minutes I''ve seen it''s easy to use and
powerful.
I''ll use transactions so if there are problems I can roll back all inserts
and update I''ve done inside a transaction scope.

I want to create a string and insert it into a record of the DB only if
not present: if it is present I want to generate another string and retry
and so on (this is the scenario when multiple users are inserting into my
tables and I need to check primary key is unique before inserting it and
not wait the eventual exception).
Can I loop until an insertion goes well or there is a better way (best
practice)?
Thanks,
Luigi.



这篇关于DbProviderFactory和交易。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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