Не удается найти объект "queuename" в sqldependency ?
I got following error in SQLDependency code Cannot find the object "QueueName" because it does not exist or you do not have permissions. I already gave permission thru following command "GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [SqlUser];" Any other permission is required for SQLDependency ? What changes required to resolved this issue . My code is string strConnectionString = @"Data Source=servername;Initial Catalog=dbname;Integrated Security=True;MultipleActiveResultSets=True;"; // To prevent errors, when database connection is lost, always stop SqlDependency subscription, before starting one. using (var connection = new SqlConnection(strConnectionString)) { // Define query. string sqlQuery = "SELECT empname from emp "; // Open connection to database. connection.Open(); using (SqlCommand command = new SqlCommand(sqlQuery, connection)) { SqlDependency.Stop(strConnectionString, "QueueName"); SqlDependency.Start(strConnectionString, "QueueName"); command.CommandType = System.Data.CommandType.Text; // Make sure the command object does not already have a notification object associated with it. command.Notification = null; // Hookup sqldependency eventlistener (re-register for change events). var dependency = new SqlDependency(command); dependency.OnChange += new OnChangeEventHandler(dependency_OnChange); // Open connection to database. if (connection.State != System.Data.ConnectionState.Open) { connection.Open(); } // Get the data from the database and convert to a list . using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { var data = new List<Process>(); while (reader.Read()) { var da = new Process { EmpName = reader.GetString(0), ToMobile = reader.GetString(1) }; data.Add(da); } _data = data; } } connection.Close(); } } return _data;
Что я уже пробовал:
I got following error in SQLDependency code Cannot find the object "QueueName" because it does not exist or you do not have permissions. I already gave permission thru following command "GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [SqlUser];" Any other permission is required for SQLDependency ? What changes required to resolved this issue . My code is string strConnectionString = @"Data Source=servername;Initial Catalog=dbname;Integrated Security=True;MultipleActiveResultSets=True;"; // To prevent errors, when database connection is lost, always stop SqlDependency subscription, before starting one. using (var connection = new SqlConnection(strConnectionString)) { // Define query. string sqlQuery = "SELECT empname from emp "; // Open connection to database. connection.Open(); using (SqlCommand command = new SqlCommand(sqlQuery, connection)) { SqlDependency.Stop(strConnectionString, "QueueName"); SqlDependency.Start(strConnectionString, "QueueName"); command.CommandType = System.Data.CommandType.Text; // Make sure the command object does not already have a notification object associated with it. command.Notification = null; // Hookup sqldependency eventlistener (re-register for change events). var dependency = new SqlDependency(command); dependency.OnChange += new OnChangeEventHandler(dependency_OnChange); // Open connection to database. if (connection.State != System.Data.ConnectionState.Open) { connection.Open(); } // Get the data from the database and convert to a list . using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { var data = new List<Process>(); while (reader.Read()) { var da = new Process { EmpName = reader.GetString(0), ToMobile = reader.GetString(1) }; data.Add(da); } _data = data; } } connection.Close(); } } return _data;
Richard Deeming
Не удается найти очередь 'SqlQueryNotificationService-{guid}'[^]