SqlDependency dependency_OnChange Info "Query" - c#

I have a very frustrating problem. My .net 4 app has been successfully using the SqlDependency object for some time to receive INSERT or UPDATE notifications from SQL server.
However the database it receives notifications from has just been updated (it is the back end to a 3rd party app so I don't know what the update entailed) and now when I restart my SqlDependency app it does not behave properly. During the StartSQLDependency() method this line triggers the dependency_OnChange event:
using (SqlDataAdapter adapter = new SqlDataAdapter(_SqlCommand))
adapter.Fill(_datatable);
With SqlNotificationEventArgs:
e.Info "Query"
e.Source "Statement"
e.Type "Subscribe"
Previously I had only seen:
e.Info "Update" or "Insert"
e.Source "Data"
e.Type "Change"
Can anyone please suggest what my have changed in the database to cause this?

I know this is old, but for future generations...
In trying to research SqlDependency triggers, I came across a CodeProject that says that an event with those parameters indicates a bad query being used for the notifications (about halfway down the article).
Microsoft has an article about the supported notification statements (for SQL Server 2008) and how to properly build them to avoid this error event.

Related

"Write" Transactions don't work when using C#/Node.js with Amazon Neptune

I am able to connect to Neptune and was able to add some data to it with no issues. However, when I tried the code at https://tinkerpop.apache.org/docs/current/reference/#gremlin-dotnet-transactions it doesn't seem to work. I receive following error:
"Received data deserialized into null object message. Cannot operate on it."
I even jumped to a JS sample (https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-transactions) and tried again. It doesn't work either.
What am I missing?
At the time of this writing, Amazon Neptune only has support for TinkerPop version 3.4.11. The "traversal transactions" semantics using tx(), that you are referencing, is new as of 3.5.2 that was released by Apache TinkerPop in mid January 2022.
Transactions are typically only required when you need to submit multiple queries but have all of the queries bounded within a single commit, or with rollback if one of the queries were to fail. If you don't need this, then each Gremlin query sent to Neptune behaves as a single transaction.
If you do need transaction-like behavior in 3.4.11, here's a link to the documentation on how to do that in Neptune using Gremlin sessions: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-sessions.html
If you don't need transactions, then here are examples of interacting with Neptune by submitting individual queries:
(.NET) https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-dotnet.html
(JS) https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-node-js.html

How to send email notification using azure to user group when there are records in a table

.I am using azure sql database with my app hosted in azure
I tried using a Automation account, created a runbook but doesnt fetch any results
FullyQualifiedErrorId : CommandNotFound Exception.
CategoryInfo :Object Not Found: (SqlAutomation/RB_Record_AzureScheduler) Command Not Found exception
You can use the "when an item is created" and the "when an item is modified" triggers for SQL in Azure Logic App to react to data changes.
You can add condition and choose an action like sending an email.
The SQL connector in Azure Logic Apps uses a polling mechanism to query a table for changes using a TIMESTAMP / ROWVERSION column. This data type is specifically designed for this kind of processing in SQL. The polling query essentially selects all rows where the rowversion is greater than the last polled value. The behavior is reliable since the column is controlled by SQL Server and the performance is extremely fast in the case where there is no new data. When there is new data, the performance is comparable to a simple row query.
For more information, please read this article and this one too.

Get notified when a cell value is changed in SQL Server database [duplicate]

This question already has answers here:
How to monitor SQL Server table changes by using c#?
(11 answers)
Closed 6 years ago.
I want to get notified when a certain change occurs in Database table. Consider the case: I want to perform a certain action when the column in a row changes its value to 5. How can I achieve it. I am using C# and entity framework to access the database.
For this you have to make a schedule job which will continuously(like interval of 5 minutes) ping database and notify you as like Facebook's notification bar.
Also you can write trigger on that table which will insert/update notification table and from there you will get notify.
The short answer is that you should probably try and manage this outside of SQL server. I have to assume that you have some application logic executing outside of SQL server that is the source of the update. Ideally your notification logic should be placed in your application tier before or after the database is updated.
Should you not be able to achieve this, three other options I can offer are:
polling You build a service that reads the value from SQL server in a loop. The loop should read the value periodically, and perform the notification. Most engineers avoid polling as from a best practices standpoint it is typically contra indicated due to adding persistent load to the database. Although polling should be avoided, it's surprisingly common in the field.
msmq You update the value via a stored procedure, and use this article to send a message to MSMQ when the value is 5. You will need to write a service to consume the MSMQ message and process the notification. You may use a WCF service using MSMQ transport to make this easy.
email You send an email using sp_send_dbmail in the update stored procedure, and build the necessary notification consumer(s). It should be noted that this method will likely also involve polling if you consume the email electronically. You can avoid that by using IMAP IDLE to process the email notifications. Try MailKit
Reporting services also apparently offers notifications, but I am not familiar with them.
using(var context = new FooEntities)
{
try
{
var customer = context.Customers.First(i=> i.CustomerID = 23);
customer.Name = "Bar";
context.SaveChanges();
//Write your notification code here
}
catch(Exception ex)
{
//Write notification along with the error you want to display.
}
}
Search in google there's many different way of displaying a notification.

Notify data was inserted into the table

Is there any way to notify working console application (call certain method) in case of any rows were added in the SQL Server 2012 DB table from anywhere?
1) One solution is to use Query Notification.
Quote:
Built upon the Service Broker infrastructure, query notifications
allow applications to be notified when data has changed.
http://msdn.microsoft.com/en-us/library/t9x04ed2(v=vs.110).aspx
https://www.simple-talk.com/sql/t-sql-programming/using-and-monitoring-sql-2005-query-notification/
2) Another solution could be
a simple AFTER INSERT/UPDATE/DELETE trigger that call sp_trace_generateevent
plus an extended events session which intercept user_event event (see here)
plus XEvent API > Microsoft.SqlServer.XEvent.Linq.dll, QueryableXEventData (see demo)

Continuous Query Notification is automatically unregistered

I am working with Oracle and ODP.Net and registering some continuous query notifications.
Everything worked fine untile the database was upgraded to 11.2.0.3 - now I see that my queries are registered and deregistered after a few seconds. The code looks like this:
OracleCommand cmd = new OracleCommand();
cmd.Connection = getOpenConnection();
cmd.CommandText = _sqlStatement;
_odep = new OracleDependency(cmd, false, 0, false);
_odep.OnChange += new OnChangeEventHandler(_odep_OnChange);
OracleDB.bindVars(ref cmd, arguments);
cmd.Notification.IsNotifiedOnce = false;
cmd.ExecuteNonQuery();
Is there a log for CQN registration somewhere on the database?
Edit: getOpenConnection() is just a function that returns an open connection, while OracleDB.bindVars just binds the existing bind variables to the command. Emphasis on the fact that everything worked fine before the DB update :)
In the end, it was a problem on the database side - incompatibility caused by registering CQN entries using the 11.2.0.1 Client on a 11.2.0.3 Server.
This may not pertain to your specific scenario but anyone having problems with CQN (and AQ) notifications not occuring should upgrade the database. There was a bug in 11.2.0.1 database.
The following SQL causes Oracle to avoid the buggy code path with the older version, but you are advised to upgrade the database:
alter system set events '10867 trace name context forever, level 1';
EDIT: Please note that this is an old bug and the problem is fixed in current patchsets. You will need to patch BOTH the database and ODP.NET to fix it.
Christian Shay
Oracle
+1 for Christian's answer (I don't have the rep to +1 it)
His fix (alter system set events '10867 trace name context forever, level 1') resolved the issue of callback events not firing.
Until that fix was applied I would see the change notification registration enter the USER_CHANGE_NOTIFICATION_REGS table and disappear when a DB change occurred, but no event would be fired.
I am using a 11.2.0.1.0 server and 11.2.0.3.0 client (http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html).

Categories

Resources