Я слежу за этим сообщением для разработки клиента для уведомления о запросе. http://www.youdidwhatwithtsql.com/started-query-notifications-sql-server-2008-r2/1676/ Я пробовал этот код как на визуальной студии, так и на моно на моем ПК, и они, похоже, срабатывают на событии onDependencyChange. Однако, когда я переношу его на малиновый pi с установленным моно-комплектом, он, похоже, не срабатывает. Я не могу отлаживать, поскольку pi находится в другом месте, и я использую SSH для удаленного доступа к нему.Событие не стреляет по малине pi mono
static void Main(string[] args)
{
Console.WriteLine ("-----------------APPLICATION STARTED------------------");
var connection = new SqlConnection(connectionString);
SqlDependency.Start(connectionString);
RefreshDataWithSqlDependency();
Console.WriteLine ("Why is it here?");
//blocks thread so you can read message
Console.ReadLine();
SqlDependency.Stop(connectionString);
}
static void RefreshDataWithSqlDependency()
{
//remove existing dependency if necessary
if (dependency != null)
{
dependency.OnChange -= onDependencyChange;
dependency = null;
}
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = new SqlCommand("SELECT ipAddress FROM dbo.dbDevices", connection);
//Create a dependency and associate it with command
dependency = new SqlDependency(command, null, 1);
//Subscribe to the SqlDependency event.
dependency.OnChange += new OnChangeEventHandler(onDependencyChange);
//Start dependency listener
SqlDependency.Start(connectionString);
//execute command and refresh data
RefreshData(command);
}
}
private static void onDependencyChange(Object o, SqlNotificationEventArgs args)
{
Console.WriteLine("ondep gets hit");
if ((args.Source.ToString() == "Data") || (args.Source.ToString() == "Timeout"))
{
Console.WriteLine("Refreshing data due to {0}", args.Source);
RefreshDataWithSqlDependency();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Data not refreshed due to unexpected SqlNotificationEventArgs: Source={0}, Info={1}, Type={2}", args.Source, args.Info, args.Type.ToString());
Console.ForegroundColor = ConsoleColor.Gray;
}
}
private static void RefreshData(SqlCommand command)
{
using (var reader = command.ExecuteReader())
{
Console.Clear();
while (reader.Read())
{
Console.WriteLine("ip = {0}", reader[0]);
}
}
}
я сейчас поставил дополнительный Console.WriteLine только по методу RefreshDataWithSqlDependency и, когда я использую Run> Run With> Microsoft .NET или Mono 4.0.2, кажется, прыгать прямо из RefreshDataWithSqlDependency, однако, когда я бегу с отладчиком он действует так, как должен. Он запустит это событие.
У меня есть проблема, когда я запустить приложение на моем ХИП с флагом отладки, Я получаю Не могу открыть сборку '--debug': Нет такого файла или каталога – Johnathon64
Итак, я решил эту проблему и добрался до конца, установил пару точек останова, которые он обязательно должен поразить и нажать на соединение. Затем я получаю свое окно SSH, но оно отображается, имя файла, имя каталога или синтаксис метки volumen неверны – Johnathon64
Предполагая, что ошибка не в том, что она не может найти вашу программу ssh? Не на вашем пути? – SushiHangover