Dear I was practicing receiving notifications of changes in the Tables with SQLTableDependency in a testing environment. I did not have any problem, but then when I took the database to a production environment (Backup and then Restore) it did not work anymore.
I saw that I regenerated the SQLTableDependency's Objects again, but I still do not receive notifications.
The documentation says that:
"Database Backup and Restore: restoring SqlTableDependency's db objects, it does not work. "
And apparently the problem is there.
I also tried without positive results:
-
Attaching the Database.
-
Manually deleting SQLTableDependency's Objects
The Code used is:
class Program
{
private static string _con = "Data Source=.;Initial Catalog=Dependency;User ID=Usuario;Password=XXXXXXXX";
static void Main(string[] args)
{
using (var dep = new SqlTableDependency<Spoolers>(_con, tableName: "Spoolers"))
{
dep.OnChanged += Changed;
dep.OnError += Error;
dep.OnStatusChanged += OnStatusChanged;
dep.TraceLevel = TraceLevel.Verbose;
dep.TraceListener = new TextWriterTraceListener(Console.Out);
dep.Start();
Console.WriteLine("Press a key to exit");
Console.ReadKey();
dep.Stop();
}
}
static void OnStatusChanged(object sender, StatusChangedEventArgs e)
{
Console.WriteLine(e.ToString());
}
public static void Changed(object sender, RecordChangedEventArgs<Spoolers> e)
{
var changedEntity = e.Entity;
Console.WriteLine("DML operation: " + e.ChangeType);
Console.WriteLine("ID: " + changedEntity.Id_Spooler);
Console.WriteLine("Id_Estado_Spooler: " + changedEntity.Id_Estado_Spooler);
Console.WriteLine("Fecha_Hora_Estado_Spooler: " + changedEntity.Fecha_Hora_Estado_Spooler.ToShortTimeString());
}
public static void Error(object sender, ErrorEventArgs e)
{
Exception ex = e.Error;
throw ex;
}
}
Is there any way to "reconnect" the program with the SQLTableDependency's Objects created ?. They have a common nomenclature.