Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a dataset through a thread

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
0
0
US
I am fetching some data inside of a thread. On the other hand, I'd like to make this data available from within a ADO compatible dataset. In other words, suppose I execute a TADODataSet from within this thread, I need to somehow represent that exact data on the outside of the thread. I already know you can't simply pass any ADO components through a thread, that's not what I'm trying to do. But I do need to somehow transfer this dataset from within the thread and expose it to the outside of the thread in an ADO compatible format.

Doing a loop and reading the dataset and all is very possible, I can create a custom dataset even. But that's not what I want to do; I need a real dataset which i can attach a data source to. There might be data-aware controls which need to access this dataset.

Arrggghhh, ADO and Threads aren't that good of friends, are they?


JD Solutions
 
Embarcadero has a link, that provides example code, slides and a paper discussing multi-threaded database applications.


Unfortunately, it also states that data aware components shouldn't be used:

"Two IMPORTANT rules to remember
RULE 1 – Database connections CANNOT be shared between threads
RULE 2 – Data-aware components should NOT be used
It takes more time to code a database application if you cannot take advantage of data-aware controls – Pad your time estimates.
ADVANTAGE – Grids holding vast amounts of data can be loaded from a thread with manageable chunks of data."

Anyway, the downloads has several sample applications..
 
Thinking about a possible solution, if you insist on using data aware controls, then one possibility is to populate a clientdataset as you get your data out of the thread. (This could possibly be very slow).

You'd also have to handle all changes (inserts/updates/deletes) to the dataset, since the data aware controls aren't tied to the actual data source.
 
Rule 1 - Yes, this I know and is why I needed to ask, and Rule 2 - If I didn't want data-aware controls, is there any light-weight dataset object (not tied to any database connection) which can be used to present the data at least? I'd like to find something already made, no need to re-invent the wheel. Speed actually is rather an issue, that's actually the whole reason it's in a thread in the first place. In this project I'm building, the whole purpose is to fire off multiple almost identical threads at the same time, let's say 5 threads for example, each getting sales for the years 2011, 2010, 2009, 2008, and 2007, each year in its own thread. Each query can take a lot of time, depending on number of sales in that year. So when each thread gets the data back, it triggers an event, and in turn the app will read from this dataset.

Sounds like something I could build myself, but again, I don't want to re-invent the wheel. I'll forget about data-aware controls.

JD Solutions
 
Is the query taking a lot of time because of the number of rows being returned, or because the query is complicated?

Maybe there can be some improvement to your actual query to optimize it.
 
very complicated query - which is looking at tons of data (in a stored procedure) but only passing back 2 values. SP query cannot be any faster, it was designed 10 years ago by Russian reporting experts, and hasn't changed actually. Just on larger databases, it can be sluggish.


JD Solutions
 
If it's just two values, it shouldn't be to slow to pass those values out of the thread through a synchronized procedure. Did you explore using a clientdataset, since you wanted to use data aware controls?

Also, since this is a lengthy query, you won't want to trigger too many of these at the same time. You may want to explore using a semaphore to limit the number of threads you spawn, to a reasonable limit.
 
Well that's not really my point though. This particular thread I'm working on at the moment is returning 2. However I'm re-building it to execute of of many different flavors of stored procedures we have for reporting. Some of them return for example the entire sales history. I'm just trying to fire multiple threads at a time to get the result back faster.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top