Sql dependency

Nr 1 Reputation point
2021-10-17T12:29:45.927+00:00

Hello friends, I want to do SQL Dependency capability in a database file without SQL management the default file is in (c:\data.mdf)
I run the service broker in the file, unfortunately I apply a record in the database, it will not be updated in another system, please help

Developer technologies Windows Forms
SQL Server Other
{count} votes

1 answer

Sort by: Most helpful
  1. Dan Guzman 9,401 Reputation points
    2021-10-19T17:10:15.037+00:00

    I see a couple of issues with the code in your image. First, need to (re)load data in the Frm_OnNewHome method. The current method does nothing after the notification so the bound data source will remain unchanged. Also, a SqlDependency stops automatically after it fires so you need to start it after each OnChange.

    Below is the full working code from a test on my machine with the Save button implementation. I ran 2 instances of the application on the same box and SqlDependency.OnChange was fired whenever the Save button was clicked on either form. I added code for the Save button, which I didn't see in your code as well as error checking for a notification subscription error.

    143028-capture1.png143122-capture2.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.