【问题标题】:SQLConnection doesn't implement IEnlistmentNotificationSQLConnection 没有实现 IEnlistmentNotification
【发布时间】:2013-01-27 20:37:17
【问题描述】:

我试图了解如何确保仅在提交事务时才将日志条目输入到文件系统中。请看下面的代码。

Using (scope As TransactionScope = new TransactionScope()) 
    'write log log file (line 2)'
    scope.complete 
End Using

在写入日志文件的那一刻,在事务范围完成之前。

我已阅读有关IEnlistmentNotification 接口的信息。我知道SQLConnection 类允许事务和分布式事务。因此我希望这个类实现IEnlistmentNotification,但它没有。为什么不呢?

【问题讨论】:

    标签: .net sql vb.net ado.net transactions


    【解决方案1】:

    IEnlistmentNotification 被资源管理器用来参与事务,但它不是由 SQL 连接或事务实现的。

    如果您实现自己的事务资源管理器,您将实现该接口并使用transactions enlistment methodsEnlistDurableEnlistVolatile 之一通知系统您要参与此事务。从此时起,您将收到对允许您对交易状态做出反应并影响交易状态的接口的调用。

    如果您想以事务方式修改文件,您必须为此实施或找到资源管理器。此资源管理器将实现IEnlistmentNotification 并通过上述登记方法参与事务。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2011-03-04
    • 2017-04-28
    • 2020-08-08
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多