Simple.Data Oracle问题(插入执行后关闭连接) [英] Simple.Data Oracle issue (closes connection after insert executes)

查看:58
本文介绍了Simple.Data Oracle问题(插入执行后关闭连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



最近我遇到了Simple.Data的一个问题,很难掌握,所以想知道是否有人对出路有更好的了解。 br />


我得到了这个(简化版):

  var  db = Simple.Data.OpenNamedConnection(myConn); 
使用 var transaction = db.BeginTransaction())
{
foreach (DataRow row in Table.Rows)
{
transaction [ Table.TableName] .Insert(行);
// 在此事务的第一次迭代之后.ConnectionState变为已关闭
}
}





所以这是一个简单的循环遍历每一行并进行插入(不要问为什么 - 这个是简化版)。这里的问题是,在第一行正常并且

事务[Table.TableName] .Insert(row); 

执行后,连接状态变为关闭并发生异常在下一次迭代中。

顺便说一下 - 这是Oracle问题,当我使用MS SQL数据库时,这段代码工作正常。



有什么想法我可能会错过吗?



谢谢!

Modestas

解决方案

< blockquote> check属性ProviderSupportsCompoundStatements - 它是一个只读属性

 使用(SimpleTransaction transaction = db.BeginTransaction ())
{
AdoAdapter adoAdapter = transaction.GetAdapter() as AdoAdapter;
if (adoAdapter!= null
{
if (!adoAdapter.ConnectionProvider.SupportsCompoundStatements)
{
// transaction.GetAdapter()。UpsertMany
}
}
}



OracleConnectionProvider没有'支持复合语句,SqlConnectionProvider可以。



https://github.com/flq/Simple.Data.Oracle/blob/master/Simple.Data.Oracle/ OracleConnectionProvider.cs

https://github.com/markrendle/Simple.Data/blob/master/Simple.Data.SqlServer/SqlConnectionProvider.cs



也许'transaction.GetAdapter()'和UpsertMany,InsertMany和UpdateMany将帮助代替使用带有'transaction'对象的foreach循环插入和更新






有一个浓缩ept称为交易范围。如果您的交易将在交易范围内,那么您的连接将不会断开连接。请参阅以下文章(特别是第14点)



TranactionScope默认属性



这将对您有所帮助。



谢谢

Sisir Patro


Hello guys,

Recently I encountered an issue with Simple.Data, that's hard to grasp so wonder if anyone has a better idea of the way out.

I got this (simplified version):

var db = Simple.Data.OpenNamedConnection(myConn);
using (var transaction = db.BeginTransaction())
{
   foreach(DataRow row in Table.Rows)
   {
      transaction[Table.TableName].Insert(row);
      // after the first iteration of this transaction.ConnectionState becomes "Closed"
   }
}



So this is a simple loop through each row and doing insert (don't ask why - this is simplified version). The problem here is that after the first row goes fine and after

transaction[Table.TableName].Insert(row);

is executed the connection state becomes closed and exception occurs during the next iteration.
By the way - this is Oracle issue and this code works fine when I am using MS SQL database.

Any thoughts what I might be missing?

Thanks!
Modestas

解决方案

check property ProviderSupportsCompoundStatements - it's a read-only property

using (SimpleTransaction transaction = db.BeginTransaction())
{
    AdoAdapter adoAdapter = transaction.GetAdapter() as AdoAdapter;
    if (adoAdapter != null)
    {
        if(!adoAdapter.ConnectionProvider.SupportsCompoundStatements)
        {
            //transaction.GetAdapter().UpsertMany
        }
    }
}


OracleConnectionProvider doesn't support compound statements, SqlConnectionProvider does .

https://github.com/flq/Simple.Data.Oracle/blob/master/Simple.Data.Oracle/OracleConnectionProvider.cs
https://github.com/markrendle/Simple.Data/blob/master/Simple.Data.SqlServer/SqlConnectionProvider.cs

Maybe 'transaction.GetAdapter()' and UpsertMany, InsertMany and UpdateMany will help instead of using foreach loop with 'transaction' object Insert and Update


Hi,

There is a concept called transaction scope. If your transaction will be inside the transaction scope then your connection will not get disconnected. Refer the following article (specifically 14th point).

TranactionScope Default Properties

This will help you.

Thanks
Sisir Patro


这篇关于Simple.Data Oracle问题(插入执行后关闭连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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