如何使用 C# 从 Oracle 数据库中检索大数据?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4651480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:24:51  来源:igfitidea点击:

How to retrieve large data from Oracle database using C#?

c#.netdatabaseoracle

提问by Mohamed

I am trying to retrieve a large amount of data from an Oracle database in .NET. I am using a .NET DBDataReaderwhich is working fine with small amount of data but when the data become medium or large it stops functioning and I have no idea why. How can i retrieve large amount of data?

我正在尝试从 .NET 中的 Oracle 数据库中检索大量数据。我正在使用 .NET DBDataReader,它在处理少量数据时运行良好,但是当数据变为中或大时,它停止运行,我不知道为什么。如何检索大量数据?

回答by HABJAN

You should try using ODP.NET. That is Oracle Data Provider written for .NET and it's much better optimized for communication with Oracle databases.

您应该尝试使用ODP.NET。这是为 .NET 编写的 Oracle Data Provider,它针对与 Oracle 数据库的通信进行了更好的优化。

Microsoft deprecated Oracle Client (System.Data.OracleClient) (http://blogs.msdn.com/adonet/archive/2009/06/15/system-data-oracleclient-update.aspx) and advised to use 3rd hand tools.

Microsoft 弃用了 Oracle 客户端 (System.Data.OracleClient) ( http://blogs.msdn.com/adonet/archive/2009/06/15/system-data-oracleclient-update.aspx) 并建议使用第三手工具。

EDITED:

编辑:

Maby you should take a look at this similar question and answer: Big Performance Problems With Oracle DataReader in .Net

Maby 你应该看看这个类似的问题和答案:Big Performance Problems With Oracle DataReader in .Net

回答by Pabuc

Ok, since you are expecting answers related to your question with very little information, answering these would help OTHERSto answer your question:

好的,由于您期望与您的问题相关的答案信息很少,因此回答这些将有助于其他人回答您的问题:

1- What is your data type in database

1-您在数据库中的数据类型是什么

2- How are you trying to fetch the data (Some code would help a lot)

2-您如何尝试获取数据(某些代码会很有帮助)

3- Are there any indexes, how big is the table and how complex is your query, have you tried optimizing it? Try writing your query.

3- 是否有任何索引、表有多大以及您的查询有多复杂,您是否尝试过优化它?尝试编写您的查询。

...

...



Ok, here is what you can try and tell us if it changed anything...

好的,这是您可以尝试并告诉我们它是否有任何改变...

static void DownloadBlob(OracleConnection myConnection)
{
  OracleCommand myCommand = new OracleCommand("SELECT * FROM table", myConnection);
  myConnection.Open();
  OracleDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
  try
  {
    while (myReader.Read())
    {
      //Obtain OracleLob directly from OracleDataReader
      OracleLob myLob = myReader.GetOracleLob(myReader.GetOrdinal("Ordinal"));
      if (!myLob.IsNull)
      {
        // I hope it is BLOB :)
      }
    }
  }
  finally
  {
    myReader.Close();
    myConnection.Close();
  }
}