dbTalk Databases Forums  

SqlDependency invalid statement

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss SqlDependency invalid statement in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Netanel Livni
 
Posts: n/a

Default SqlDependency invalid statement - 03-19-2007 , 11:54 AM






Hello,

I am trying to use the SqlDependency object to maintain a current dataset on
my client code. However, whenever I try to implement it, the event fires
with the following Arguments in the SqlNotificationEventArgs object:

e.Info = Invalid
e.Source = Statement
e.Type = Subscribe

The command I am creating the SqlDependency on implements the following
stored procedure:

ALTER PROCEDURE WorkItemsGet
AS

SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
SET ARITHABORT ON

SELECT
JobID,
MachineName
FROM
dbo.T_WorkItems

The Code I have written is as follows:

private SqlConnection connection;
private SqlCommand command;
private SqlDependency dependency;
private DataSet dataToWatch;

private void Form1_Load(object sender, EventArgs e)
{


dataToWatch = new DataSet();

connection = new SqlConnection(GetConnectionString());
connection.Open();
command = new SqlCommand(); //GetSQL(), connection);
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "WorkItemsGet";

dependency = new SqlDependency(command);
bool success = SqlDependency.Start(GetConnectionString());
dependency.OnChange += new
OnChangeEventHandler(dependency_OnChange);

SqlDataAdapter adapter = new SqlDataAdapter(command);

adapter.Fill(dataToWatch);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dataToWatch.Tables[0];
}


void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
try
{
SqlDependency dependency = sender as SqlDependency;
dependency.OnChange -= dependency_OnChange;

command.Notification = null;

dependency = new SqlDependency(command);
dependency.OnChange += new
OnChangeEventHandler(dependency_OnChange);

dataToWatch.Clear();

SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dataToWatch);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dataToWatch.Tables[0];
}

Does anyone have any idea what is wrong with my setup?

Thanks.


Reply With Quote
  #2  
Old   
Jens K. Suessmeyer
 
Posts: n/a

Default Re: SqlDependency invalid statement - 03-23-2007 , 06:55 AM






I dont know off the top of my head if you used nay restricitons in your
stored procedure, but some settings will invalidate the querysubscription
like SET NOCOUNT ON and other ones mentioned here:
http://msdn2.microsoft.com/en-us/library/aewzkxxh.aspx

Perhaps you should try to get rid of some of the settings one by one, to see
if they are making your subscriptions to be invalid.

Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---


"Netanel Livni" <NetanelLivni (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hello,

I am trying to use the SqlDependency object to maintain a current dataset
on
my client code. However, whenever I try to implement it, the event fires
with the following Arguments in the SqlNotificationEventArgs object:

e.Info = Invalid
e.Source = Statement
e.Type = Subscribe

The command I am creating the SqlDependency on implements the following
stored procedure:

ALTER PROCEDURE WorkItemsGet
AS

SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
SET ARITHABORT ON

SELECT
JobID,
MachineName
FROM
dbo.T_WorkItems

The Code I have written is as follows:

private SqlConnection connection;
private SqlCommand command;
private SqlDependency dependency;
private DataSet dataToWatch;

private void Form1_Load(object sender, EventArgs e)
{


dataToWatch = new DataSet();

connection = new SqlConnection(GetConnectionString());
connection.Open();
command = new SqlCommand(); //GetSQL(), connection);
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "WorkItemsGet";

dependency = new SqlDependency(command);
bool success = SqlDependency.Start(GetConnectionString());
dependency.OnChange += new
OnChangeEventHandler(dependency_OnChange);

SqlDataAdapter adapter = new SqlDataAdapter(command);

adapter.Fill(dataToWatch);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dataToWatch.Tables[0];
}


void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
try
{
SqlDependency dependency = sender as SqlDependency;
dependency.OnChange -= dependency_OnChange;

command.Notification = null;

dependency = new SqlDependency(command);
dependency.OnChange += new
OnChangeEventHandler(dependency_OnChange);

dataToWatch.Clear();

SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dataToWatch);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dataToWatch.Tables[0];
}

Does anyone have any idea what is wrong with my setup?

Thanks.



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.