Active Directory 是否支持事务?
简单的问题,但我在任何地方都找不到答案:Active Directory 是否支持事务?
换句话说,以下更改是否会回滚(因为我没有调用scope.Complete()):
using (var scope = new TransactionScope())
{
DirectoryEntry entry = ...;
entry.Properties["givenName"].Value = "New Given Name";
entry.CommitChanges();
}
如果没有,是否可以以某种方式启用此功能? 现在,我有执行数据库更新和相应 AD 更新的代码,并且在 AD 更新因某种原因失败时我有补偿逻辑。 这个解决方案远非最佳。
亲切的问候, 罗纳德·维尔登伯格
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是——不。 ActiveDirectory 本质上是一个 LDAP 实现(带有一些奇特的扩展,但其核心仍然是 LDAP)。 LDAP 协议和规范都没有事务的概念,因此这实际上是不可能的。
可以在客户端模拟事务,但您必须自己执行此操作或使用 Spring,我相信它会为您执行此操作 - 显然这不如您期望的服务器端事务那么安全一个数据库。 关于 Spring 的注释 - 我还不能完全确定 Spring.NET 支持 LDAP 的“事务”,但在 Spring 的 Java 实现中它们有类似的东西。 也许值得一看。
通过阅读 CommitChanges 方法的文档,它只是说它将您的更改发送到服务器 - 如果它没有指出它们是事务安全的,我会认为它们不是。
一些随机的想法 - 我猜想 Microsoft 可能会在 ActiveDirectory 上添加类似的内容(因为它不仅仅是 LDAP),但如果他们愿意的话,他们可能不会还没有。
Short answer is - no. ActiveDirectory is essentially an LDAP implementation (with some fancy extensions but at it's core it is still LDAP). Neither the LDAP protocols nor the specs have the concept of transactions so this really isn't possible.
It would be possible to emulate transactions on the client side but you'd have to do that yourself or use Spring which, I believe, will do that for you - obviously this is not as safe as server side transactions that you'd expect from a DB. A note on Spring - I'm not completely sure that Spring.NET supports 'transactions' for LDAP yet but they have something like that in the Java implementation of Spring. It might be worth a look.
From reading the docs on the CommitChanges method it just says that it sends your changes to the server - if it doesn't make a point of saying that they are transaction safe I would assume that they're not.
Some random thoughts - I guess it would be possible that Microsoft could add something like this onto ActiveDirectory (as it is more than just LDAP) but they probably won't if they haven't yet.
不。LDAP 不直接支持事务,但是,可以通过编写实现 IEnlistmentNotification 接口的登记类来“推出您自己的”解决方案。 IEnlistmentNotification 适用于 System.Transactions 命名空间中的显式和隐式事务。
您可以在此处找到更多文档(和示例):https://msdn.microsoft.com/en-us/library/system.transactions.ienlistmentnotification(v=vs.110).aspx
No. LDAP doesn't directly support transactions, however, it is possible to 'roll your own' solution by writing an enlistment class that implements the IEnlistmentNotification Interface. IEnlistmentNotification works with both explicit and implicit transactions in the System.Transactions namespace.
You can find more documentation (and an example) here: https://msdn.microsoft.com/en-us/library/system.transactions.ienlistmentnotification(v=vs.110).aspx