问题描述
我的系统将一些数据写入SQL Server DB(2008),稍后将其提取并进行更多处理,然后再将其写入Oracle(10g)DB.
My system write some data to a SQL Server DB (2008), extracts it later and processes it some more, before writing it to an Oracle (10g) DB.
我已经将SQL Server交互包装在TransactionScope中,但是当我尝试与Oracle交互进行相同的思考时,我会收到"TranactionAbortedException-事务已中止".
I've wrapped my SQL Server interactions in a TransactionScope but when I try the same think with my Oracle interactions I get a `TranactionAbortedException - "The transaction has aborted".
删除TransactionScope,一切正常.
Remove the TransactionScope, and everything works OK.
我总是可以恢复到手动管理自己的交易,但是我希望有一个简单的解决方案.
I could always revert back to manually managing my own transactions, but I'm hoping there is a simple solution.
示例代码:
private static void OracleTest()
{
using (TransactionScope ts = new TransactionScope())
{
using (OracleConnection conn = new OracleConnection(connString))
{
try
{
using (OracleCommand cmd = new OracleCommand())
{
cmd.CommandText = "MyPackage.MyFunction";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection = conn;
OracleParameter param = cmd.Parameters.Add(new OracleParameter("field1_", "abc123"));
param = cmd.Parameters.Add(new OracleParameter("rs_", OracleType.Cursor));
param.Direction = System.Data.ParameterDirection.Output;
conn.Open();
using (OracleDataReader dr = cmd.ExecuteReader())
{
我没有发现任何暗示您不能在Oracle中使用TransactionScopes的信息,但是正如您从我的示例中看到的那样,我们处于第一个障碍(打开连接时),因此很难看到我可能在哪里出错了.
I haven't found anything to suggest that you can't use TransactionScopes with Oracle, but as you can see from my example, we're falling at the first hurdle (when we open the connection) so it's hard to see where I might be going wrong.
推荐答案
您可能想看一看.我在Oracle 10g中对TransactionScope也不太满意: http://forums .oracle.com/forums/thread.jspa?messageID = 4127323
You may want to take a look at this; I haven't had much luck with TransactionScope in Oracle 10g either: http://forums.oracle.com/forums/thread.jspa?messageID=4127323
这篇关于将TransactionScope与System.Data.OracleClient一起使用-TransactionAbortedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!