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.
In shared hosting because they restrict some features, so i was unable to use
SqlDependency
, but here is my solution to Play notifications without SqlDependency in asp mvcIf you are new
signalR
, then first try this post to create simple chat web application.My requirement was to play notifications when new sales happens in shops
1. Create SignalR Server Hub
SignalR server hub class that sends messages to all clients browser.
2. Javascript Send Method in PlaceOrder View
When a customer places new order for this shop then the following javascript code Calls the Send method on the server hub to update clients.
3. Javascript Client Call Back Method in ShopSales View
The hub class on the server calls this javascript function to push content updates to each client.
Used
Howler.js
Plugin to play notification , check this post.Hope helps someone.