473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SqlDependency in WinFormsApp

Hey all,

I tried to use SqlDependency in WinFormsApplication to show up with new
information upon a change in a SqlResult.
The Problem I have is that the OnChangeEvent is fired when I create the
SqlDependency, but not again afterwards.
Any idea on that?

Source:

namespace sql_dependency
{
public partial class Form1 : Form
{
public System.Data.SqlClient.SqlConnection SqlConn;
public Form1()
{
InitializeComponent();

System.Data.SqlClient.SqlDependency.Start([serverconnectionstring]);
SqlConn = new
System.Data.SqlClient.SqlConnection([serverconnectionstring]);
}

private void SqlSelect_TextChanged(object sender, EventArgs e)
{
if(SqlSelect.Text == String.Empty)
DepCheckActivateBtn.Enabled = false;
else
DepCheckActivateBtn.Enabled = true;
}

private void DepCheckActivateBtn_Click(object sender, EventArgs e)
{
// Assume c is an open SqlConnection.
SqlConn.Open();
// Create a new SqlCommand object.
System.Data.SqlClient.SqlCommand cmd = new
System.Data.SqlClient.SqlCommand("SELECT * FROM MyTestTable", SqlConn);
// Create a dependency and associate it with the SqlCommand..
System.Data.SqlClient.SqlDependency dep = new
System.Data.SqlClient.SqlDependency(cmd);
// Maintain the refence in a class member.
// Subscribe to the SqlDependency event.
dep.OnChange += new
System.Data.SqlClient.OnChangeEventHandler(SqlResu ltChanged);
// Execute the command.
cmd.ExecuteReader();
// Process the DataReader.
}

private void SqlResultChanged(object sender, EventArgs e)
{
MessageBox.Show("Result changed!");
}
}
}
Nov 17 '05 #1
2 6654
Hi Stefan,

It seems that this is a Whidbey issue. Currently, Whidbey is still in beta
version, and Whidbey issues are not in support boundary. I suggest you post
such issue in:
http://forums.microsoft.com/msdn/

This forum is on Whidbey discussion, and you will get much more useful
replies.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #2
Hi Stefan,

Thanks for posting your code here. The code seems to be fine. Do you mean
that the OnChange event fired once when the SqlDependency was created and
then never fired again? Please try to remove the following line to have a
try. Because SqlDependecy.Start starts monitoring the the dependency
changes on the connection string, not the command result set.

System.Data.SqlClient.SqlDependency.Start([serverconnectionstring]);

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: J055 | last post by:
Hi I've been trying out SqlCacheDependency using the ObjectDataSource and SQL Server 2005. It all works quite well with the minimum of configuration, e.g. <asp:ObjectDataSource...
1
by: mrink1074 | last post by:
One of the method options for this is to use the connection string from the web.config file, the other is to use the Command object. What if my connection strings are not stored in the web.config...
1
by: Nadia Amir | last post by:
I have a database which is very frequently updated .I want an option that user can specify that after how many minutes he/she wants to see those changes . Like a mechanism which would do 1.....
0
by: MattC | last post by:
I have the following code. I get an initial Subscribe event but then I get no notification in the app. I call SqlDependency.Start(DatabaseProviderHelper.ConnectionString); on the web app...
0
by: das | last post by:
Hello all, I am using the SqlDependency to subscribe to any new inserts into a database table, I enabled the DB to be borker ready and subscrbed to Query notifications on the database. My C#...
2
by: Toni | last post by:
Hello! I'm trying to use ASP.NET caching with my web site and SQL Server, but I have a problem. I try to do everything according to the instructions like this page here:...
1
by: | last post by:
Hey Guys, I have been struggling with this for few days. when i use SqlCacheDependency sqlDependency=new SqlCacheDependency("test","dbo.USStates"); where test is the name of...
0
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, We are planning to use SqlCacheDepency in our application(ASP.Net2.0/SQL Server 2005).I was just doing a POC and found the Cache addition and invalidation is behaving abnormally. I just wanted...
1
by: JDeats | last post by:
I have a WinForms app (.NET 2.0) which has a web service reference and the web service call is failing inside some corporate environments. I know a proxy server could cause this problem, but does...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.