C # OracleDependency OnChange disparando varias veces

It is my understanding that the OracleDependency can be tied to monitor a query (not just a table). I make 2 command objects and 2 dependency objects but the query for both have different where clauses so they should be looking at 2 different subsets of this table.

I assign both of these dependency objects to the same callback. My expectations are that when I change something in the table that one of these dependency objects are watching that the OnChange event would fire for that one. I would then be able to do the following in the OnChange event to get the query that triggered teh change:

OracleDependency OraDep = (OracleDependency)sender; string sql = (string)OraDep.RegisteredResources[0];

So I setup 2 queries against the same table with a different where clause value. Then I go into the DB and change one of them but to my surprise the OnChange even fires twice and the above code to get the query shows both queries.

Is there no way to have the dependency for a specific query and not the entire table? I thought I read somewhere you set it up for a specific query, where clause and all.

preguntado el 16 de mayo de 11 a las 19:05

1 Respuestas

Oracle change notification monitors the objects not queries. Any change on the table new record inserted, updated or deleted, new column added, renamed/dropped. Thats the reason why you are seeing notifications 2 times.

One way is to call the stored procedures instead of queries. Accept only 1 notification. Notification event e.info tells you what operation it is either insert/ update/ delete. So you can write an if condition to only respond to insert notifications and based on that you can call the appropriate sp or query.

Espero que esto ayude.

contestado el 16 de mayo de 11 a las 23:05

I guess I have a problem then. In this change event I need to know what changed. There doesn't seem to be anything that I can see to show me this information. It seems odd as I've seen examples that have a where clause on the cmd they pass but yeah I can see that doesn't seem to be the case, but that still leaves me with needing to know what changed from my C# application. - user441521

Let me clarify of what "what changed" means. I mean the record that changed (when the msg type is update) and not just what table changed (as I'd know that anyway since I setup the cmd). - user441521

@user441521 Since you are only interested in update. In the event handler u can have a if condition to if(e.info.ToString() == "Update") { Process } else ignore. - Naveen Chakravarthy

Yeah that wasn't enough to know what record got updated. I figured it out though. In the command object that you attach to the dependency object you set the include row id to true, then inside the callback event args for the dependency onchange, you can get the oracle rowid(s) and query the table to get the records that changed. Thanks. - user441521

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.