简体   繁体   English

SqlDependency搞乱了应用程序属性

[英]SqlDependency messes up application properties

In C# windows forms application in main Form constructor I have the following code (updated to the actual code from the app): 在主窗体构造函数中的C#Windows窗体应用程序中,我有以下代码(已从应用程序更新为实际代码):

SqlDependency.Stop(Properties.Settings.Default.EmployeeHealthDB, Properties.Settings.Default.NotificationQueueName);
        IsUsingSqlDependency = SqlDependency.Start(Properties.Settings.Default.EmployeeHealthDB, Properties.Settings.Default.NotificationQueueName);

SQL dependency works intermittently and quite often I am getting following error on the second statement: SQL依赖项间歇性地工作,并且经常在第二条语句中出现以下错误:

Properties.Settings.Default.ConnStr 'System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings' and no extension method 'Settings' accepting a first argument of type 'System.Windows.Forms.PropertyStore' could be found (are you missing a using directive or an assembly reference?) Properties.Settings.Default.ConnStr'System.Windows.Forms.PropertyStore'不包含'Settings'的定义,并且找不到扩展方法'Settings'接受类型为'System.Windows.Forms.PropertyStore'的第一个参数(您是否缺少using指令或程序集引用?)

As you can see the first statement refers to exactly the same settings values and it doesn't fail. 如您所见,第一条语句引用的设置值完全相同,并且不会失败。

On occasions when this part works the application is able to catch database changes and do what I want it to do, but it may give an error on application exit (on Form Closing event) where I use the same exactly statement (as first one) to stop dependency as above. 有时,当这部分工作时,应用程序可以捕获数据库更改并执行我想要的操作,但是在应用程序退出时(在窗体关闭事件中),如果我使用完全相同的语句(与第一个语句一样),则可能会出错。停止如上所述的依赖性。 The debugger doesn't provide any useful information, no stack information available. 调试器不提供任何有用的信息,没有可用的堆栈信息。 The error can be either SqlException or the same as above. 该错误可以是SqlException或与上面相同。

I just ran my application 6 times (in debugger) - without changing anything and without doing anything within the application - just open main form and close main form. 我只运行了我的应用程序6次(在调试器中)-无需更改任何内容,也无需在应用程序内执行任何操作-只需打开主窗体并关闭主窗体即可。 First two times I got the error on SqlSDependency.Start, then next 4 times it ran just fine. 前两次我在SqlSDependency.Start上收到错误,然后下4次它运行正常。

Using VS 2013 Professional, .NET 4.5, C#. 使用VS 2013 Professional,.NET 4.5,C#。 Building on Win 7 x64 but generated code is for x32 bit systems. 在Win 7 x64上构建,但生成的代码用于x32位系统。

I thought that using dependency was a great idea because users wanted to see changes made by other users without manually refreshing data but I am struggling. 我认为使用依赖关系是个好主意,因为用户希望查看其他用户所做的更改,而无需手动刷新数据,但是我很挣扎。

Adding application namespace as in the linked article provided by mjwills resolved my issue. 如mjwills提供的链接文章中所述,添加应用程序名称空间解决了我的问题。

Properties does not exist in the current context 当前上下文中不存在属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM