0
프로젝트에서 데이터베이스 테이블 중 하나에서 모니터를 유지해야하며 새 레코드를 삽입 할 때 클라이언트에서 동일하게 업데이트해야합니다.SqlDependency 변경은 하나의 변경에만 적용됩니다.
이 경우 서비스 브로커를 구독하려면 SqlDependency
을 사용하고 있습니다. 또한 SignalR을 사용하여 클라이언트 측을 즉시 업데이트합니다.
제 질문은 : 내 구독은 하나의 변경 만 유효합니다. 한 번의 업데이트 만 받으면 내 구독이 자동으로 제거됩니다.
SqlDependency.Start(connectionString);
SubScribeForAttendance();
SqlDependency.Stop(connectionString);
구독 기능 :
public void SubScribeForAttendance()
{
// We have selected the entire table as the command, so SQL Server executes this script and sees if there is a change in the result, raise the event
string commandText = @"Select bnr,knrhex From dbo.TableName where bnr > SomeId";
// Start the SQL Dependency
SqlDependency.Start(connectionString);
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(commandText, connection))
{
connection.Open();
var sqlDependency = new SqlDependency(command);
sqlDependency.OnChange += Dependency_OnBookingChange;
// NOTE: You have to execute the command, or the notification will never fire.
using (command.ExecuteReader())
{
}
}
}
}
당신은 SQL 종속성에게 통지가 트리거 될 때마다 다시 등록해야
그래서 다시에서이 솔루션 유일한 옵션은 가입을 발견? 여러 변경 사항을 등록 할 수 없습니까? –
아니요, SQL Server는 하나의 변경 사항 만 등록합니다. 일단 트리거되면 훅을 해제합니다. –
문제가 해결되면 내 답변을 수락 할 수 있습니까? 감사 –