By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Advice !

P: n/a

jzlondon wrote:
Hi,

I have a question that I wonder if someone might be able to help me with...

I have an application which handles real-time financial data from a third
party source. The data comes in via events which are fired on an arbitrary
thread, and I then take the data, generate update commands for a SQL Server
database, and add them to a queue using a lock on a sync object to ensure
thread safety when writing to the queue.

I then have a background worker thread which watches the queue and executes
the queries inside it sequentially. Again, the reading and dequeuing is
synchronised with the writing.

So far, so good.

I also have a need to execute some other, fairly slow running, queries
against the database. These queries will return results and will be running
in an arbitrary thread. The question I have is about thread safety around
the SQLConnection object. So far, I've avoided locking on it, as I only
have one thread (the worker) accessing it at any point.

Do I need to synchronise access to the connection object? If so, can I open
a separate connection and sync that, leaving the first connection free to
process the updates, or will connection pooling interfere and give me any
problems?

Thanks in advance for any advice you may have,

James Cane

ps. .Net 2.0, C#, SQL Server 2005.

Hi,
Just for precaution, I think you should sync the connection
object. Actually, I faced a lot of weird errors which originated from
these kind of thread sync problem. The queries don't execute when such
exceptions occur. As you told that the application was related to some
financial domain, I would stress on synchronizing the connection
object.
If you don't want to synchronize connection object then, you will
have to open create and use new connection object each time when you
want to fire some query. To read more about my personal experience
about the exceptions please visit my blog -
http://anants-blog.blogspot.com/

Hope you don't get such kind of errors !

Oct 2 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.