TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sanket Jain
NA
855
140.9k
Cannot find the object "QueueName" in SQLDependency ?
Feb 26 2018 6:09 AM
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;
Reply
Answers (
4
)
I Have one doubt for Classic ASP.net
how to write connection string automatically in web.config f