none
Intermitent [KeyNotFoundException] when calling [SqlDependency.Start] RRS feed

  • Question

  • Good day MS,

    AS mentioned [KeyNotFoundException] is being thrown intermitently as a result of calling [SqlDependency.Start].  Summary as follows:

    • This is a WinForms application
    • We're creating named queues using : CREATE QUEUE & CREATE SERVICE [x] ON QUEUE
    • On a dev. server everything is running under a sysadmin account for testing and elimination purposes
    • When queues are freshly created and application is run from IDE, all is well, notications are being sent and detected
    • Changes to the DB are made using both the winforms app as well as direct entries into the table
    • To further test stability sometimes manual DB entries are made without the winofroms app running
    • Due to above entries made, on certain unknown occasions the queue created (call it xxxChangeMsgLog) starts to fill with entries
    • If this happens and the app is run, the exception [KeyNotFoundException] is thrown
    • The app contains one [SqlDependency.Stop(ConnectionStringValue, QueueName)] & one [SqlDependency.Start(ConnectionStringValue, QueueName)]
    • If the queue for example had 3 hanging entries, running the app and having the .Stop called and waiting for the Start to crash would result in one message being dropped out of the queue.  Repeating these steps as many times as there are messages in the queue eventually clears the messages and the application works and detects changes again
    • Different combinations of Starts and Stops have been used but nogo
    • Whether the app crashes or not however seems to highly depend on that message queue as when it is clean all is well

    Your assistance in this matter is highly appreciated as well as your time.

    Best regards,

    K. Fityani

    • Moved by Pawel Marciniak Tuesday, September 7, 2010 4:48 PM (From:SQL Service Broker)
    Friday, September 3, 2010 6:50 PM

Answers

  • Yes, this is a known limitation with SQLDependency.  The KeyNotFoundException is due to SqlDependency trying to locate an app domain key that it expects to be there.    Essentially it is telling you that the message was not destined for this particular application instance.  

    There is no plan to change this behavior, we were just planning on documenting it as a limitation of SqlDependency.

    Monday, September 27, 2010 5:41 PM
    Moderator