SqlNotificationInfo

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

To capture changes in the database I am using SQLDependency. When the change
is notified I update my UI.

In the handler for OnChangeEvent I checked what type of info is passed to
the method argument. I find out it is "Error"

In MSDN I read it is an Internal Server Error.

However, when I ignore this error, my app works just fine (at least it seems
to). What does mean that error?

Thanks,

Lubomir
 
Someone who actually got SqlNotifications to work? I thought that capability
was just an urban legend...
 
I have an application that runs on a server which is updating stock prices
every 15 minutes from external data sources.

I have an other application that runs on users' PC. This application is
using a SQLDependency object to automatically refresh one of the screen when
changes occurs in the database. It was a bit tough to setup but it is now
working great.

--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc. (http://www.emoreau.com/)
 
You have any good references to point to beyond what's on MSDN? I've been
trying to fire notifications based upon events occuring in the database and
so far, the only result I've had is to lock up the database. I've posted a
couple of questions in the forums without any response, so I figured that
SqlNotifications was just vaporware. Except for this post, I've not heard of
anyone (outside of Microsoft) who actually got the scheme working. The
hazard I run into is that most developers seem to be working for large
companies where they have unlimited amounts of time to get jerked around by
features and functions that do not work "as advertised", so ultimately they
do get it resolved. Unfortunately, my clients do not fund time for me to
explore every nook and crany of some obscure object or feature that doesn't
work the way Microsoft describes it. Even something as trivial as a bug in a
Microsoft control can disrupt my day, so you can imagine where
SqlNotifications falls in that continuum.
 
Here is some code that I got working for a demo:

Option Strict On

Imports System.Data

Imports System.Data.SqlClient

Public Class Form1

Private mintChangeCount As Integer

Private mds As New DataSet

Private Delegate Sub UICallback()

Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetData.Click

GetData()

lblInfo.Text = "Aucun changement"

mintChangeCount = 0

btnGetData.Enabled = False

txtSQL.Enabled = False

End Sub

Private Sub GetData()

Dim cn As SqlConnection = Nothing

Try

mds.Clear()

cn = New SqlConnection("Data Source=.\sql2005; " & _

"Integrated Security = true; " & _

"Initial Catalog = AdventureWorks")

'cn = New SqlConnection("Data Source=.\sql2005; " & _

' "Integrated Security = true; " & _

' "Initial Catalog = HedgeFund_PRD")

Dim dad As New SqlDataAdapter(txtSQL.Text, cn)

Dim dependency As New SqlDependency(dad.SelectCommand)

AddHandler dependency.OnChange, AddressOf Me.DataChanged

SqlDependency.Start(cn.ConnectionString)

dad.Fill(mds, "Data")

grdDemo.DataSource = mds

grdDemo.DataMember = "Data"

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

Private Sub DataChanged(ByVal sender As Object, ByVal e As
SqlNotificationEventArgs)

mintChangeCount += 1

Me.Invoke(New UICallback(AddressOf RebindOnUIThread))

End Sub

Private Sub RebindOnUIThread()

GetData()

lblInfo.Text = String.Format("{0} changements.", mintChangeCount)

End Sub

'Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

' txtSQL.Text = "SELECT MAJDate FROM dbo.DatabaseEvent WHERE Event =
'BloombergUpdate'"

'End Sub

End Class


--


HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc. (http://www.emoreau.com/)
 
I've spoken to a number of customers/developers that have been able to get
SqlNotifications to work. At one point in time I included a Notification
Services demo in my sessions. However, I found that I ended up having to
provide so many warnings about its use and where it makes sense (and where
it does not) that I dropped it from my sessions. Unless you're well aware of
the implications and what's being done behind the scenes to support this
technology, it's tough to get working correctly or to design it into your
application.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
Earl:
Open MSDN help, and in search tab enter: Using Query Notifications
It will point you to the page with links related to notifications and
SQLDependency.

If you want you can email me: itlk at yahoo dot com

It seems I will not get the answer here, what could be the origin of
SqlNotificationInfo.Error I get from DB. Wired it is, that everything works
fine otherwise, as I get notification regularly in required intervals and
after reloading the table, everything looks fine.

Regards,

Lubomir
 
I've read all the Query Notifications stuff in MSDN, it sounded good in
theory, didn't work out in practice. When I get back to the Notification
side, I will take you up on your e-mail offer. Thanks.
 
Thanks Eric for the sample. Unfortunately I had to move on and will have to
revisit that issue as soon as possible. Without examining your code sample
in detail, I will note that it appeared my issues were more on the SqlServer
capability side rather than client-side.
 
Did you check the details about received notifications?

I expected I will receive the "Insert" type, but I get Error (even after
ignoring it all works OK) Why Broker is sending an error when DB is updated.

Thanks,

Lubomir
 
I only touch on it--nothing substantive.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
Darn. Thanks.

Robin S.
--------------------
William (Bill) Vaughn said:
I only touch on it--nothing substantive.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
Back
Top