如何在SQL Compact 4.0和NHibernate中使用TransactionScope

编程入门 行业动态 更新时间:2024-10-25 06:21:44
本文介绍了如何在SQL Compact 4.0和NHibernate中使用TransactionScope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将NHibernate与.NET的TransactionScope对象结合使用.到目前为止,我已经成功地使用了Oracle 11g和SQL Server 2008R2,没有任何问题.但是,SQL Compact似乎已面目全非.

I am trying to use NHibernate in combination with .NET's TransactionScope object. So far I have successfully used Oracle 11g and SQL Server 2008R2 with no issues. However, SQL Compact seems to fall on its face.

using (var scope = new TransactionScope(TranactionScopeOption.Required)) { using (var session = _sessionFactory.OpenSession()) { // The line below throws. I also tried passing in System.Data.IsolationLevel.ReadCommitted to no avail using (var txn = session.BeginTransaction()) { // Perform insert txn.Commit(); } } scope.Complete(); }

这导致以下异常.我知道这是什么意思,但我不明白为什么为什么尝试创建嵌套事务.

This results in the following exception. I understand what this means, but I don't understand why it is attempting to create a nested transaction.

NHibernate.TransactionException: Begin failed with SQL exception ---> System.InvalidOperationException: SqlCeConnection does not support nested transactions. at System.Data.SqlServerCe.SqlCeConnection.BeginTransaction(IsolationLevel isolationLevel) at System.Data.SqlServerCe.SqlCeConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction(IsolationLevel isolationLevel) at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel) at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel)

推荐答案

我认为答案就在这个问题上:无法在交易范围内征用连接对象

I think the answer lies in this question: The connection object can not be enlisted in transaction scope

猜测中,TransactionScope需要升级为分布式或嵌套事务,CE都不支持."

"At a guess, TransactionScope needs to escalate to a distributed or nested transaction, neither of which is supported by CE."

更多推荐

如何在SQL Compact 4.0和NHibernate中使用TransactionScope

本文发布于:2023-11-03 06:38:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   SQL   Compact   TransactionScope   NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!