1

I am trying to create application that showing the rows from table in SQL to DataGridView in System Windows Forms Application

The problem is when I am updating the row directly from SQL Management Studio / Other application was Adding / Deleting / Updating the row in the table, my application isnt showing the latest row

I want my application showing the up to date rows in real time (even the other program change the table rows, I want my application displaying updated rows)

How to resolve this?

Thanks

CXO2
  • 628
  • 10
  • 28

3 Answers3

0

What you want is the MS SQL Server facility called "SQL Query Notifications", introduced here: http://technet.microsoft.com/en-us/library/ms130764.aspx.

Be forewarned, it is not simple and it may have some scaling issues for multiple clients.

A good tutorial implementation is here: http://www.codeproject.com/Articles/144344/Query-Notification-using-SqlDependency-and-SqlCach

Explanations of the scaling concerns and how to deal with them are in these other SO questions:

https://stackoverflow.com/a/14875804/109122

Is there a scalable alternative to SQL Server Query Notifications for raising events in an application from SQL Server?

Community
  • 1
  • 1
RBarryYoung
  • 55,398
  • 14
  • 96
  • 137
0

You can use the SqlDependency Class. Its intended use is mostly for ASP.NET pages (low number of client notifications).

ALTER DATABASE UrDb SET ENABLE_BROKER

Implement the OnChange event to get notified:

    void OnChange(object sender, SqlNotificationEventArgs e)
    And in code:

    SqlCommand cmd = ...
    cmd.Notification = null;

    SqlDependency dependency = new SqlDependency(cmd);

    dependency.OnChange += OnChange;

It uses the Service Broker (a message-based communication platform) to receive messages from the database engine.

Thilina H
  • 5,754
  • 6
  • 26
  • 56
-1

Create trigger on insert operation. This trigger must fire update event for you application. Aplication recieve event and update table.

You neet only choose communication protocol

Pokimon
  • 3
  • 1
  • 4
  • 1
    You might want to explain how you think "*This trigger must fire update event for you application*" can be done, because it's far from obvious what you mean here. – RBarryYoung Sep 25 '13 at 15:15
  • yes please explain more detailed about "trigger update event" – CXO2 Sep 25 '13 at 15:20