Click here to Skip to main content
15,891,719 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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");

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.
Posted
Updated 31-Mar-11 6:05am
v2
Comments
[no name] 31-Mar-11 11:40am    
What environment is this for, web or Windows?
Obopeng 1-Apr-11 4:08am    
Hi Mark thank you for you contribution. It is a windows app.
Dylan Morley 31-Mar-11 11:51am    
What version of .Net framework, do you have 4.0 and access to Tasks?
Obopeng 1-Apr-11 4:10am    
I am using .Net 3.5 framework. Thank u for your contribution too.
Dalek Dave 31-Mar-11 12:06pm    
Edited for Readability and Code Blocks.

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

C#
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);


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 :)
 
Share this answer
 
Comments
Dalek Dave 31-Mar-11 12:06pm    
Good Call.
Marlinspike00 7-Aug-13 18:10pm    
This is a good halfway measure, in that it allows you to do other things, but you still have a thread that is sitting waiting for the database server to process the query.

Unfortunately, Oracle doesn't offer a true asynchronous Begin/End style approach to database operations.
Albin Abel 31-Mar-11 12:40pm    
Good Call
 
Share this answer
 
Comments
Obopeng 1-Apr-11 4:22am    
Tnx for all your inputs.

I tried to use examples from these links:
http://aspadvice.com/blogs/azamsharp/archive/2007/04/05/Executing-a-Query-Asynchronously-in-.NET-2.0.aspx

http://www.csharphelp.com/2007/07/asynchronous-data-access-using-callback-model/

The above links are similar thing that I want to do. There problem is that the examples are for SQL Server db and I am using Oracle db. I get an error when I try to use things like: "Asynchronous Processing=true" and BeginExecuteReader as shown in the database. Once again I highly appreciate all your contribution.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900