I am trying to implement a SqlDependancy to fire events when a change is made to one of the tables in MySQL server database, however the event does not seem to fire when I make alterations to the table through SSMS, why could this be?
My implmentation below is inline with Microsofts tuturiol:
public int GetVehicleCount(bool monitorCount)
{
int count;
string query = "SELECT AREA_ID, VEHICLE_COUNT, ADDED_ON FROM CAPACITY_LOG";
using (var sql = DBClass.Instance.OpenSqlConn())
using (var cmd = new SqlCommand(query, sql))
{
SqlDependency sqlDependancy = new SqlDependency(cmd);
sqlDependancy.OnChange += new ChangeEventHandler(VehicleCount_Changed);
using (var reader = cmd.ExecuteReader())
{
//Do something
}
return 0;
}
}
private void VehicleCount_Changed(object sender, SqlNotificationEventArgs e)
{
//throw new NotImplementedException();
}
I have made sure of the following:
- The connection to the database can be opened.
- The database has the Service-Broker enabled.
- The SqlDependancy has been started.
- No exceptions are being thrown during runtime
Note that the event fires once shortly after it has been subscribed to and never again, below are the values of the event args: