Hello,
I have enabled Sql service broker to monitor change notification for specific table. But RecordChangedEventArgs is not getting fired when i make update to the products table. Here is my code.
public void SubscribeTableDependency(string connectionString)
{
tableDependency = new SqlTableDependency
tableDependency.OnChanged += TableDependency_OnChanged;
tableDependency.OnError += TableDependency_OnError;
tableDependency.Start();
}
public void TableDependency_OnChanged(object sender, RecordChangedEventArgs
{
if (e.ChangeType.ToString() == "Update")
{
// Message
}
}
Emily FosterPosted Mar 5, 2025, 6:14 AM
It appears that you are using SqlTableDependency to monitor changes in a specific table in your database but are encountering an issue where the RecordChangedEventArgs is not triggering when updates are made to the "tProducts" table. This can be a bit tricky to troubleshoot, but let's explore some possible reasons why the OnChanged event might not be firing in your scenario:
1. Check SQL Server Configuration: Ensure that the SQL Server Service Broker is correctly enabled on your database where the "tProducts" table resides. Without this feature enabled, SqlTableDependency won't be able to receive notifications for data changes.
2. Permissions: Make sure that the user account used in the connection string has the necessary permissions to listen for notifications in the SQL Service Broker.
3. Table Name Case-Sensitivity: Ensure that the table name specified in the SqlTableDependency constructor exactly matches the case of the table in your database. SQL Server is case-insensitive by default, but C# may be case-sensitive.
4. Debugging: You can add some logging or debugging statements within your TableDependency_OnChanged method to see if it is being called at all. This can help narrow down whether the issue lies in the event not firing or in the event handler itself.
5. Error Handling: Since you have an OnError event handler, make sure to log any errors that may occur during the process. It's possible that an error is preventing the OnChanged event from being triggered.
6. Data Model Matching: Double-check that the model TIpwProjectCopyQueue you are using in your SqlTableDependency matches the structure of the "tProducts" table in your database. Any discrepancies here could cause issues with change detection.
By reviewing these aspects of your implementation and considering the suggestions above, you may be able to identify the root cause of the RecordChangedEventArgs not triggering in your SqlTableDependency setup. If you continue to experience issues, further debugging and possibly refining your code based on the insights gained from these checks may lead to a resolution.