System.InvalidOperationException: When using SqlDependency without providing an options value, SqlDe

Posted by SheoNarayan under Error and Solution on 4/9/2011 | Points: 10 | Views : 9944 | Status : [Administrator] | Replies : 3

Problem:
I was getting below error while working with Push SQL Cache dependency

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


Solution:
As hinted in this error, it occurs if you do not use the SqlDependency.Start method before instantiating the connection object. So the solution is to use SqlDependency.Start method and pass the connection string as parameter.

 SqlDependency.Start(_connStr);
// get the connection
using (SqlConnection conn = new SqlConnection(_connStr))
{

}


Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com



Responses

Posted by: Vuyiswamb on: 4/9/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Thanks for sharing :)


Thank you for posting at Dotnetfunda
[Administrator]

SheoNarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 4/9/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Welcome !

Regards,
Sheo Narayan
http://www.dotnetfunda.com

SheoNarayan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 4/11/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Thanks sheo!!!

Thanks
Karthik
www.f5Debug.net

SheoNarayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response