PC Review


Reply
Thread Tools Rate Thread

SqlDependency in WinFormsApp

 
 
Stefan
Guest
Posts: n/a
 
      29th Sep 2005
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(SqlResultChanged);
// Execute the command.
cmd.ExecuteReader();
// Process the DataReader.
}

private void SqlResultChanged(object sender, EventArgs e)
{
MessageBox.Show("Result changed!");
}
}
}
 
Reply With Quote
 
 
 
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      30th Sep 2005
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.

 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      30th Sep 2005
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."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would anti-virus software prevent a web service call from a WinFormsapp? JDeats Microsoft C# .NET 1 2nd Oct 2008 05:25 PM
Fatal error 682 and SqlDependency Efran Cobisi Microsoft ADO .NET 3 21st Feb 2006 12:10 PM
Enable sqldependency caching sql server 2005 =?Utf-8?B?TmVtbw==?= Microsoft Dot NET Framework 0 13th Feb 2006 02:17 PM
How can I get SqlDependency to work with CLR Stored Procedures =?Utf-8?B?Um9iZXJ0IFp1cmVy?= Microsoft ADO .NET 0 19th Dec 2005 04:57 AM
SqlDependency minimum permissions =?Utf-8?B?TWljaGFlbCBWYW5ob3V0dGU=?= Microsoft ADO .NET 0 31st Oct 2005 04:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:45 AM.