473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Multithreaded Asynchronous Database queries problem

Hi all,

I've got a minor problem that I think deals with synchronization.
I've got asynchronous socket code working on my server. When it
recieves a command, it will call the follow function to perform an
asynchronous SQL query on my database:

SyncLock pgConn
strSQL = "SELECT * FROM usertable"

pgCommand = New CoreLab.PostgreSql.PgSqlCommand(strSQL, pgConn)
pgDataReader = pgCommand.BeginExecuteReader(AddressOf
dbQueryReturn, _netclient, CommandBehavior.Default)
End SyncLock

But here is my problem. The asynch command is saving the result to
pgDataReader, which is privately declared in the module (yes, module.
Bad coding practice :D ). I'm figuring that is bad, as all the
results will be stored there and overwrite the last.

So, I'm in a quandry. Can I put another SyncLock in the callback
delegate (dbQueryReturn) on the pgDataReader to prevent other threads
from modifying it until it is copyied to a local variable? Wouldn't
that negate the benefit of asynch programming though?

Should I create a new class instance for each DB query, and keep the
dataobjects in there? I was avoiding that because that is a lot of
additional overhead (a string, command and reader object per query,
plus the class overhead itself).

Should I keep a "pool" of datareaders privately declared in the
module? As they are used, I can change a state property for each
object to used, and pass the index as the state object for the asynch
call. Then on the callback delegate, the state object is used to get
the datareader object from the pool. When it is done, the object is
returned to "free" state. Would also allow me to dynamically increase
or decrease the number of pooled readers, depending on load (and thus
save some memory)

Last idea. Would it be possible to create a new DataReader object,
then pass as the state object? Or is that not a "legal move"?

Thanks, I really appreciate it.
Jul 21 '05 #1
0 1465

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sam | last post by:
Hi, When I load my form I start a new threads that creates a datareader, which gets data from my database. The problem is that I'd like to be able to abort the thread when clicking on another...
0
by: Zach Tong | last post by:
Hi all, I've got a minor problem that I think deals with synchronization. I've got asynchronous socket code working on my server. When it recieves a command, it will call the follow function to...
6
by: John | last post by:
Hi I have a vb.net app that opens an access database runs several sql action queries on the tables and closes the db. This is done every few minutes. The problem is that sometimes I get an error...
2
by: ncht | last post by:
i am facing a database connectiion problem that i have writen code with connect to the database using ADODB , and i am sure that the connection is made an execution of query can be done succefully...
6
by: DNB | last post by:
I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using asp.net tree view to display hierarchical data and...
3
by: DNB | last post by:
I did post this message in C# group also... I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using...
3
eboschi
by: eboschi | last post by:
Hi all, i'm new to .net programming and i have some problems with database connection. I have written two web application. Both of them use ADODB Connection to Sql Server 2000 database. The problem...
6
by: praveenb000 | last post by:
we hosted a website http://vijayawadanalanda.org developed using asp.net and back end MS Accees database. There is some database connectivity problem occurring when saving the information in...
4
dsatino
by: dsatino | last post by:
Ok, I'm not going to post any code at this point because there's a lot and I'm pretty sure my break point is caused outside of the module it's showing in. I have a local table that is a line item...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.