SqlDependency

I just checked the SqlDependency object in .NET Whidbey Beta 2.  As I remember, in Beta 1, you had to iterate through the data that was returned.  In Beta 2, I just tried it and you don't have to iterate through the rows that are returned (unless that is happening behind the scenes and I don't know it).

        Dim strSql As String = "select col1, col2, col3 from owner.tablename"
        Dim sqlDr As SqlDataReader
        sqlCn = New SqlConnection(ConnectionString)
        sqlCm = New SqlCommand(strSql, sqlCn)
        sqlCn.Open()
        sqlDep = New SqlDependency(sqlCm)
        sqlDr = sqlCm.ExecuteReader()
        sqlDr.Close()
        AddHandler sqlDep.OnChange, AddressOf DependencyChangeCallBackFunction

I tested the code above, and my event handler fired when I made my change.  Nice.

Wally

3 Comments

  • HI

    I tried using SQL Dependency but it is getting fired again and again without even any event occurs. I am not able to understand why. I used one code which was running perfectly and then i copied it and wrote my own code with my own variable. But it seems that its OnChange event is getting fired again and again

  • Even I am facing the same problem that it is getting fired again and again without even any event.

  • I had this issue. The reason that caused me because I hadn't used dbo.TableName in my query. Check this. Belive me, it resolved it

Comments have been disabled for this content.