Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : When Using SqlDependency Without Providing an Options Value

I am working on query notification. I have created Queue, Service and Route in my Database. I am accessing my Database on Network by IP Address, so i created a Route in Sql Server like this..

ALTER ROUTE [NotificationMessagesRoute]   
WITH  SERVICE_NAME  = N'MyNotificationService' ,  
ADDRESS  = N'TCP://myIPAddress:PortNo' --

on FrontEnd it have used SqlDependency like this..

SqlDependency dependency = new SqlDependency(command), "Service=MyNotificationService;local database=Test", int.MaxValue);

Its working Perfectly, if i am using Local Connection String and also Route in Sql Server as Local, but if i access DB on my organizations local Network, it do not show me notification on new Insertion.

I have also used SqlDependency object as below, but it gives me below Error.

 SqlDependency dependency = new SqlDependency(command);

Error : When using SqlDependency without Providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.

Plz Help...

like image 932
Shahid Iqbal Avatar asked Jan 12 '23 05:01

Shahid Iqbal


1 Answers

Add start the dependency in Startup class

System.Data.SqlClient.SqlDependency.Start(ConnectionString);
like image 72
sankara pandian Avatar answered Jan 26 '23 01:01

sankara pandian