我是 SQL Server 查询通知的新手,我需要一些时间来理解它。
我的目标是创建一个 Windows 服务应用程序,当对 SQL Server 表进行更改时,该应用程序会收到通知。我遵循了本指南,这对我入门很有帮助。
但是我无法得到预期的结果。OnStart()我的 Windows 服务应用程序中的方法如下所示:
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("Service Started");
serviceRun = false;
SqlClientPermission perm = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
try
{
perm.Demand();
eventLog1.WriteEntry("permission granted");
}
catch (System.Exception)
{
eventLog1.WriteEntry("permission denied");
}
try
{
connstr = "Data Source=THSSERVER-LOCAL;Initial Catalog=ET;User ID=mujtaba;Password=ths123";
connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand("select * from dbo.Customer_FileUploads", connection);
// Create a dependency and associate it with the SqlCommand.
SqlDependency dependency = new …Run Code Online (Sandbox Code Playgroud)