I am using SqlDependecy
with signalR
to push notifications to client browser when there is some database changes, I followed this and this post and everything works fine in local SqlExpress
version 11.0 with Local Connection String , but i have some kind of permissions problem when i connect to remote database hosted in GoDaddy with Production Connection String
Working Local ConnectionString
<!--<add name="NotifyConnection" providerName="System.Data.SqlClient" connectionString=
"Data Source=.\SQLExpress;Initial Catalog=TestDB;Integrated Security=SSPI;" />-->
Production ConnectionString
<add name="NotifyConnection" connectionString="Server=000.00.00.000;Database=TestDB;
User Id=UserName;Password=YourPassword;" providerName="System.Data.SqlClient" />
Get Data Method
public IEnumerable<Order> GetData()
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings
["NotifyConnection"].ConnectionString))
{
using (SqlCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = "SELECT OrderID,CustomerID FROM dbo.[RestUser]";
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>() // Here the Error throws
.Select(x => new Order()
{
OrderID = x.GetInt32(0),
CustomerID = x.GetInt32(1)
}).ToList();
}
}
}
What i have tried ?
I followed this post to Grant permissions in sql server , but not sure is this correct method to follow.
USE YourDatabaseName;
CREATE QUEUE NameChangeQueue;
CREATE SERVICE NameChangeService ON QUEUE NameChangeQueue ([http://schemas.microsoft.com/
SQL/Notifications/PostQueryNotification]);
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO YourUserName; // Here i get this error:
//Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema,
sys, or yourself.
ALTER DATABASE YourDatabaseName SET ENABLE_BROKER; // Broker is already enabled
Screen Shot:
I am new to SqlDependency
, how to fix this issue ?
Any help would be great.