2

I have a question about the usage of SqlDependency in .NET. I've read the documentation, but it's still not clear to me if the OnChange event gets called in its own thread. So for example, if I get 30 concurrent events, do they each get their own OnChange even handler? The reason I'm asking is I don't want to create an engine with this if the work that's being done in the OnChange handler is blocking the next event.

For example, I have a SqlDependency for an Orders database, and every time there's a new order, I receive the OnChange event and then I can process the user's order. This will not hold up others coming in, correct?

Also, do you see any problems using this method? SqlDependency seems like a really powerful feature, so I hope it works this way. ;)

Thanks

1 Answer 1

4

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx

According to a note in the msdn info on the SQLDependancy Class in the link above, quote->

"The OnChange event may be generated on a different thread from
 the thread that initiated command execution. "

On the other hand, on the same page is the following note, quote->

"SqlDependency was designed to be used in ASP.NET or middle-tier 
 services where there is a relatively small number of servers 
 having dependencies active against the database. It was not 
 designed for use in client applications, where hundreds or
 thousands of client computers would have SqlDependency
 objects set up for a single database server. "
Sign up to request clarification or add additional context in comments.

3 Comments

Again, very vague information. "may be generated on a different thread" doesn't quite answer my question. As for the second part, and as you've seen from the example in my question, this is on a middle-tier (taking customer orders). So, will this ever block additional events or will it handle ALL CONCURRENT EVENTS in their own thread?
Also, how do other medium-sized websites handle these kind of transactions where you need to take action on an update and then process data to another database, where there are chances for error and will need to be processed again?
I currently have a windows service running on the database machine with a sqldependency on the Orders database, and for every insert, I'm process and dispatching the data to another server's database. If the dispatching fails, I set a timer in the windows service for one minute intervals to go through any unprocessed orders. I have to assume that this is a VERY COMMON SCENARIO. How do other web applications do this? This is the only way that I can think of making it work, so I wanted to know if processing would be blocked for any or all concurrent orders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.