在.C#中异步使用Oracle数据库 [英] Using Asynchronously in .C# to Oracle database

查看:232
本文介绍了在.C#中异步使用Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我目前正在开发一个定制的应用程序,该应用程序需要从Oracle数据库表中提取数据并在网格中进行预览,然后用户单击导出"以将其导出到文本文件.

该表包含大量交易数据,返回结果花费了很长时间.
我已经对该查询进行了优化,因此我无能为力.
我希望用户能够在等待数据返回或至少批量返回数据的同时执行其他工作.

我尝试异步使用,但是使用以下连接字符串时出现连接问题:

Hi there,

I am currently working on a bespoke application that needs to extract the data from Oracle database table and preview it in a grid before the user click export to export it to text file.

The table contains huge transactional data and it takes long to return results.
There is nothing much I can do with the query as I have already optimized it.
I want the user to be able to perform some other work while waiting for the data to return or at least return data in batches.

I tried to use Asynchronously, but I am getting connection problem when using the following connection string:

conn = new OracleConnection("Data Source=111.00.000.11:port/SID;Persist Security Info=True;User ID=username;Password=pwd;  Asynchronous Processing=true");


我得到:异步处理"是无效的连接字符串属性".

我也不能使用BeginExecuteReader,因为它没有在OracleCommand中定义.

错误4
''Oracle.DataAccess.Client.OracleCommand'' does not contain a definition for ''BeginExecuteReader'' and no extension method ''BeginExecuteReader'' accepting a first argument of type ''Oracle.DataAccess.Client.OracleCommand'' could be found (are you missing a using directive or an assembly reference?)

任何人都会想出如何解决这个问题的方法,或者关于我可能解决的整体建议的任何建议.

感谢您的及时帮助.


I get: ''Asynchronous Processing'' is an invalid connection string attribute''.

I also can''t use BeginExecuteReader as it is not defined in OracleCommand.

Error 4
''Oracle.DataAccess.Client.OracleCommand'' does not contain a definition for ''BeginExecuteReader'' and no extension method ''BeginExecuteReader'' accepting a first argument of type ''Oracle.DataAccess.Client.OracleCommand'' could be found (are you missing a using directive or an assembly reference?)

Anyone will ideas how I can get around this or any advice regarding my overall possible solution around this.

Thank you in-advance for your prompt help.

推荐答案

如果您使用的是.Net 4.0,则可以使用任务和延续"来包装数据访问.例如

If you''re on .Net 4.0, you can use Tasks and Continuations to wrap your data access. E.g.

var context = TaskScheduler.FromCurrentSynchronizationContext();

var task = Task.Factory.StartNew(() =>
{
    DataTable data = SomeSortOfDatacontext.GetOrders();
    return data;
});

task.ContinueWith(data =>
{
    DataTable data = data.Result;
    foreach(Row row in data.Rows)
    {
        // blah blah blah
    }
},
System.Threading.CancellationToken.None,
TaskContinuationOptions.OnlyOnRanToCompletion, context);



关于Tasks的好处是,它通过提供SynchronizationContext
自动处理到UI线程的编组.
否则,您可以使用 ThreadPool [IAsyncResult [



The good thing about Tasks is that it automatically handles marshalling to the UI thread by providing a SynchronizationContext

Otherwise, you could just use the ThreadPool[^] or IAsyncResult[^]

Lots of options available to achieve this :)


尝试以下方法

这篇关于在.C#中异步使用Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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