Query Notification - Duplicate OnChange Events Fired

Jul 17, 2007

Hi all,



I am investigating using Query Notifications - a great addition BTW. I have built a test app - loosely based on MSDN example - and am running against a SQL Express 2005 server. I have the following problem:



I have start/stop buttons to enable change checking, and a hardcode query that I am using for testing. If I stop and restart I now recieve duplicate notifcations, a single change causing the OnChange event to fires twice with two different ids Repeat this and the event will fires 3 times for each change and so on.

This only happens with a running app, if I restart the app I only get a single notification so I assume I have missed a step in stopping query notifcations or reinitialisation. I have include code below:



private bool Start()

{

try

{

// Remove any existing dependency connection, then create a new one.

SqlDependency.Stop(_currentConnectionString);

if (SqlDependency.Start(_currentConnectionString))

{

if (connection == null)

{

connection = new SqlConnection(_currentConnectionString);

}

if (command == null)

{

command = new SqlCommand(_sqlQueryString, connection);

}

return (true);

}

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}

return false;

}

private void Stop()

{

SqlDependency.Stop(_currentConnectionString);

if (command != null)

{

command.Notification = null;

command = null;

}

if (connection != null)

{

connection.Close();

connection = null;

}

}

private void GetDataSnapshot()

{

// Empty the dataset so that there is only

// one batch of data displayed.

dataToWatch.Clear();

// Make sure the command object does not already have

// a notification object associated with it.

command.Notification = null;

// Create and bind the SqlDependency object

// to the command object.

SqlDependency dependency = new SqlDependency(command);

dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

using (SqlDataAdapter adapter = new SqlDataAdapter(command))

{

adapter.Fill(dataToWatch, tableName);

}

}

private void dependency_OnChange(object sender, SqlNotificationEventArgs e)

{

// This event will occur on a thread pool thread.

// Updating the UI from a worker thread is not permitted.

// The following code checks to see if it is safe to

// update the UI.

ISynchronizeInvoke i = (ISynchronizeInvoke)this;

// If InvokeRequired returns True, the code

// is executing on a worker thread.

if (i.InvokeRequired)

{

// Create a delegate to perform the thread switch.

OnChangeEventHandler tempDelegate = new OnChangeEventHandler(dependency_OnChange);

object[] args = { sender, e };

// Marshal the data from the worker thread

// to the UI thread.

i.BeginInvoke(tempDelegate, args);

return;

}

// Remove the handler, since it is only good

// for a single notification.

SqlDependency dependency = (SqlDependency)sender;

dependency.OnChange -= dependency_OnChange;

// At this point, the code is executing on the

// UI thread, so it is safe to update the UI.

++changeCount;

lblStatus.Text = String.Format(statusMessage, changeCount);

// Add information from the event arguments to the list box

// for debugging purposes only.

//lbChanges.Items.Clear();

lbChanges.Items.Add("+++++++++++++++++");

lbChanges.Items.Add("Id: " + dependency.Id);

lbChanges.Items.Add("Info: " + e.Info.ToString());

lbChanges.Items.Add("Source: " + e.Source.ToString());

lbChanges.Items.Add("Type: " + e.Type.ToString());

// Reload the dataset that is bound to the grid.

if (e.Info != SqlNotificationInfo.Error)

this.GetDataSnapshot();

}



Thanks, Nick



View 3 Replies


ADVERTISEMENT

IDTSComponentEvents' Events? When Are They Fired?

Sep 25, 2006

Hi everyone,

I was wondering when events inside IDTSComponentEvents interface are called when you throw a SSIS package? I've got a private class which implements IDTSEvents and along with that got another one that implements the IDTSComponentEvents. I see how neither of them are fired when I debug the code by using F11, and I don't know what is it for.

Let me know your comments or come back to me if you need further details on that.

Thanks in advance,

View 4 Replies View Related

Multiple OnPreExecute Events Fired

Mar 21, 2007

Is it possible to only handle the outter-most event? For example, I have an email that goes out in response to OnPreExecute and OnPostExecute, but I only want it to go out once, instead of for every tasks/object.

Thanks,

Rick

View 1 Replies View Related

Trigger Not Fired For CREATE_LOGIN And ALTER_LOGIN Events

Mar 4, 2008

Hi,

I've created the following trigger:

CREATE TRIGGER myTriggerServer
ON ALL SERVER
FOR CREATE_LOGIN, ALTER_LOGIN, DROP_LOGIN
AS
BEGIN
EXEC myDatabase.dbo.myProcedure
END

The trigger is NOT fired (and procedure not executed) when I create a new login or alter an existing login.
Only Drop Login fires the trigger.

Please tell if it's a problem with SQL Server 2005 or am I making some mistake here?

-Anshul

View 4 Replies View Related

Outbound SOAP Notification For DML Events

Jan 11, 2008

I'm using a SQL-2005 DB to manage TFS Build Information. I need to create a SOAP web service call in response to an INSERT in the Builds table.
I am, however, thoroughly confused about the most efficient way to do this. The best I can come up with is to create a CLR function that takes the build number from the DB Insert statement, creates the XML and sends the msg to my already published (and already being used) WebService. The CLR function would be called in a trigger set of by the insert.

I don't suppose there is a native way to generate outbound SOAP msgs based upon DML events?

View 3 Replies View Related

Wrong Query Fired

Apr 19, 2006

By Database is heavily used , we use Transaction log backups ever 10 minuts, now someone fired a wrong query , that updated a particular table , the DB is still in use, there are some users working on it , I cant get the DB offline , what can I do to correct the mistake , please advice.

View 7 Replies View Related

Last Query Statement Fired Into The MSSQL Engine

Jan 8, 2007

Hi,

How can you get the Query Statement of the last executed SQL command.

I am not quite sure but I do remember coming across such a command ( maybe an undocumented one).

Thanks for your help and pointers.

My Best wishes for the new year to all the folks in the forum. Wishing you greater days ahead.

Warm Regards,
Ranjit S Hans.

---------------------------------------------------------------------
Everywhere is a walking distance if you have the time - Steven Wright

View 4 Replies View Related

SQL Server Error Logs: What Events Is It Logging? Can We Edit And Include DDL Events?

Jun 20, 2007

Hello experts. I have been searching for anything about this but found very little. What are the events logged in SQL Server Error Logs aside from Successful/Failed Login, Backup/Restore/Recover database and, start/init sql server? Can we configure this to log other events, like CREATE or DBCC events for example? If so, how? Thanks a lot.

View 1 Replies View Related

Events Calendar Questions: How To Find Events In The Week End

Jan 28, 2006

I have a start date, end date for each event.

I want to list all events between the start and end date comes in Saturday or Sunday.
in SQL server 2005 TSQL statement.

any insights ?

View 1 Replies View Related

Transact SQL :: Emailing Session Events For Extended Events

Feb 3, 2014

I am using this code for LongRunning Queries.

CREATE EVENT SESSION LongRunningQuery
ON SERVER
ADD EVENT sqlserver.sql_statement_completed
(
ACTION (sqlserver.sql_text, sqlserver.tsql_stack)
WHERE sqlserver.sql_statement_completed.duration > 60000

[Code] ...

Here Instead of writing to XML file how can send an EMAIL if a query runs more than 1 minute in my server ?

View 2 Replies View Related

SQL Query Automatically Count Month Events B4 Today; Count Events Today + Balance Of Month

Mar 20, 2004

I would like to AUTOMATICALLY count the event for the month BEFORE today

and

count the events remaining in the month (including those for today).

I can count the events remaining in the month manually with this query (today being March 20):

SELECT Count(EventID) AS [Left for Month],
FROM RECalendar
WHERE
(EventTimeBegin >= DATEADD(DAY, 1, (CONVERT(char(10), GETDATE(), 101)))
AND EventTimeBegin < DATEADD(DAY, 12, (CONVERT(char(10), GETDATE(), 101))))

Could anyone provide me with the correct syntax to count the events for the current month before today

and

to count the events remaining in the month, including today.

Thank you for your assistance in advance.

Joel

View 1 Replies View Related

Calculating Total Events (query)

Jan 23, 2008

Hi. I'm trying to calculate the total number of cases that more than 4 events. This is my query:

select count(defendanteventpros.vbkey) as countcase from defendanteventpros
where exists (select * from defendanteventpros where eventid=2 and eventdate between '1/1/2007' and '12/31/2007')
having count(defendanteventpros.vbkey)>4

The defendanteventpros table has a vbkey (primarykey) eventid (type of event) and an evetndate (when the event takes place).

What I'm trying to find is how many cases had 4 or more events and were received (eventid=2 from above) between 1/1/2007 and 12/31/2007.

I keep getting a big number that I know is not correct. I would appreciate any help anyone can offer! Thanks!

View 7 Replies View Related

Help Me Optimize A Daily Events Query

Nov 1, 2006

We keep a database of events that are classified by severity. I've got a good, efficient query that gives me the grand total for these events. And I have a bad slow query that breaks down the information into daily totals.

My fast query will count the totals for 3213586 events in 4 seconds. The slow daily query takes about 60 seconds for each day.

Please help optimize my slow query!

------ Database schema is:












Column Name
Data Type
Length
Allow Nuls

1
msrepl_tran_version
uniqueidentifier
16
0

0
[time]
GMTtime (int)
4
0

0
msec
int
4
1

0
offset
GMToffset (smallint)
2
0

0
type
nameType (varchar)
15
1

0
host
nameType (varchar)
15
1

0
process
nameType (varchar)
15
1

0
dbName
nameType (varchar)
15
1

0
ptName
nameType (varchar)
15
1

0
description
descType (varchar)
47
1

0
rtuName
nameType (varchar)
15
1

0
groupName
nameType (varchar)
15
1

0
message
msgType (varchar)
131
0

0
fgInt
tinyint
1
1

0
sevInt
tinyint
1
1

0
key1
int
4
1

0
key2
int
4
1

0
spooler
tinyint
1
1

------- The database view eventView that's used by my queries:
SELECT DATEADD([second], [time] + 60 * offset, '01/01/70') AS timeStr, msec, host, process, dbName, ptName AS point, description, rtuName AS rtu, groupName, message, type, sevInt, [time]
FROM dbo.summary

------- Fast totals query:

select
(select count(*)
from [event].[dbo].[eventView]) as Events,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 1)as Low,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 2)as Medium,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 3) as High,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 4) as Low1,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 6) as Medium1,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 8) as High1,
(select count(*)
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 9) as High2

------- Slow daily query:

declare @myDay datetime
declare @begDay datetime

declare @myTable
table( myDay datetime,
Events int,
Low int, Medium int,
High int, Low1 int, Medium1 int,
High1 int, High2 int )

select @myDay = getdate()

select @begDay = convert(datetime, '10/01/2006')

while @begDay <= @myDay
begin

insert into @myTable (myDay) values (convert(varchar(20), @begDay, 101))

---------------------------------------------------------------------

update @myTable set Events =
(select count(*) as Events
from [event].[dbo].[eventView]
where
convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set Low =
(select count(*) as Low
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 1
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set Medium =
(select count(*) as Medium
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 2
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set High =
(select count(*) as High
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 3
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set Low1 =
(select count(*) as Low1
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 4
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set Medium1 =
(select count(*) as Medium1
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 6
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set High1 =
(select count(*) as High1
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 8
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

update @myTable set High2 =
(select count(*) as High2
from [event].[dbo].[eventView]
where type = 'alarm' and sevInt = 9
and convert(varchar, timeStr, 101) = convert(varchar(20), @begDay, 101))
where myDay = convert(varchar(20), @begDay, 101)

---------------------------------------------------------------------

select @begDay = dateadd(day,1,@begDay)

end

select * from @myTable

View 15 Replies View Related

Query Notification

Oct 30, 2007



hi,

When SQL server notifies the application that the records in a table has changed, is there a way to know which record has changed from the application?

Let me give an eg.


Consider that we have a table customer. We have registered for a notfication for 2 customers, say Cust id 1 and Cust id 2. Now , when records for these two customers changes we get a notification. Is there a way in .Net by whihc we can get whihc customer has been modified?


Thanks
Man.

View 4 Replies View Related

Query DateTime DataType For Current Or Future Events

Oct 12, 2006

I have a sql server express 2005 database with a table named Events with a column named Date (datetime datatype).  I want a query that will display all rows that are either current or future but not past.  I suspect there is a simple way of doing this.  As a Newbie searching archived threads this is what I have come up with so far.  I determine the number of days from present:SELECT DATEDIFF(day, Date, GETDATE()) AS NumberOfDays FROM EventsThis yields number of days from present with positive numbers in the past and negative numbers in the future.  Thus setting a WHERE clause to <= 0 would limit my results to present or future events.  Something like this:SELECT * FROM EventsWhere DATEDIFF(day, Date, GETDATE()) AS NumberOfDays <= 0The error message states: "Incorrect syntax near the keyword 'AS'"This feels like a clumsy way to approach this problem, but I have to start where I am.Any suggestions on how to proceed will be greatly appreciated.

View 2 Replies View Related

SQL Server 2012 :: Right Way To Query Extended Events Session?

Jun 4, 2015

I use this code in a utility procedure (for performance testing) but it is really slow.

For example, a session with three events is taking 5 seconds to complete this query:

DECLARE @xml xml=
(
SELECT CAST(xet.target_data AS xml)
FROM sys.dm_xe_session_targets AS xet
JOIN sys.dm_xe_sessions AS xe
ON (xe.address = xet.event_session_address)
WHERE xe.name = @name
);

with data as

(
select
convert(varchar(128),convert(varbinary(128),'0x'+n.value('(action[@name="context_info"]/value/text())[1]','varchar(128)'),1)) context
, n.value('(data[@name="duration"]/value/text())[1]','int')/1000.0 duration
, n.value('(data[@name="cpu_time"]/value/text())[1]','bigint')/1000.0 cpu_time
, n.value('(data[@name="physical_reads"]/value/text())[1]','bigint') physical_reads

[code].....

So, I was wondering (considering the buffer is usually only holding a few hundred events)

1. Is this the wrong way to query data from a ring buffer?

2. Is there any way to make this code quicker?

3. Is it better to target a file store rather than a ring buffer for this?

select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003D
D8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000

[Code] .....

View 6 Replies View Related

SqlDependency OnChange Problem

Jan 4, 2008

Hi,

I have a windows application in C# that pretty much is a copy of the example found in http://msdn2.microsoft.com/en-us/library/a52dhwx7.aspx although I am using a different database.

My problem is that the SqlDependency event OnChange is firing all the time although on insert, update or delete is performed in the database. The event fires approximately 1000times in one minute!

Does anyone have a solution to this problem?

Thanks
/Jonas Djurback

View 7 Replies View Related

Getting SQLDependency To Fire The OnChange

Oct 20, 2006

After many problems with permissions I have got got SQL to accept a notification request but the public static void OnChange(object sender, SqlNotificationEventArgs e) is never triggered. The notification registers and de-registers ok. The same connect string successfuly connects to the same database to process queries.

I can see the GUID suffixed stored procedure, queue and service being created. Where does SQL2005 store the address/name of the routine it is to trigger? (When the notification is cancelled, the guid-siffixed items disappear) I have looked at the generated stored procedure, queue and service, but there is no indication of what is to be called back.

I have followed the instructions at http://msdn2.microsoft.com/en-us/library/ms181122.aspx, but so far without avail. I have checked the Application and system event logs, but there is indication therein. Also the SQL log.

So my questions are:

1) Where is the callback stored (is it a pointer or an actual name) ?

2) What steps should I take to resolve this?

View 7 Replies View Related

SqlDependency.OnChange() Not Firing

Aug 2, 2006

I am running

ALTER DATABASE dbname SET ENABLE_BROKER

on my app startup and then SqlDependency.Start(), and then the following code

SqlCommand cmd = con.CreateCommand();

cmd.CommandText = "SELECT request_queue.track_id, track.file_name, track.track_number, track.track_name, " +

"artist.artist_id, album.album_id, artist.artist_name, album.album_name " +

"FROM dbo.request_queue INNER JOIN track on request_queue.track_id=track.track_id " +

"inner join artist on track.artist_id=artist.artist_id " +

"inner join album on track.album_id=album.album_id";

cmd.CommandType = CommandType.Text;

if (con.State != ConnectionState.Open)

con.Open();

dep = new SqlDependency(cmd);

dep.OnChange += new OnChangeEventHandler(dep_OnChange);

SqlDataReader rdr = cmd.ExecuteReader();

List<Track> l = new List<Track>();

while (rdr.Read())

{

Track t = new Track();

t.TrackID = (int)rdr["track_id"];

t.Filename = (string)rdr["file_name"];

if (rdr["track_name"] != DBNull.Value)

t.TrackName = (string)rdr["track_name"];

t.TrackNumber = (int)rdr["track_number"];

l.Add(t);

}

rdr.Close();





and for some reason, after i do multiple changes to the request_queue table, (adding rows), the dep_on_change never fires, and if i check dep.HasChanges it is always false.

View 8 Replies View Related

Query Notification Problem

Jul 17, 2007

I've got an application that's using query notifications with a two-user setup (a user that starts the dependency running, and an application user that subscribes to it). I'm having problems getting the query notifications to go through however... according to the Profiler, when the application user does something that triggers a query notification, it causes this error:

This message could not be delivered because the user with ID [application user] in database ID [database] does not have permission to send to the service. Service name: SqlQueryNotificationService-[guid].

The problem is that [guid] is different each time, and there doesn't seem to be a generic "grant send on all services" statement, so I can't grant send on the particular service in question to the application user to get rid of the error. (If I grant db_owner to the application user, the problem goes away and everything works, but I'd rather not do that. The application user already has subscribe query notifications, receive on QueryNotificationErrorsQueue, and references on contract::...PostQueryNotification.)

Obviously I'm doing something wrong, but I am completely out of ideas and can't seem to find anything new to try. Any ideas? Thanks.

View 3 Replies View Related

HOW TO: Unsubscribe From A Query Notification

Oct 26, 2007

After having problems with SqlDependency logging an infinite number of errors I've rewritten my code to use SqlNotificationRequest instead. Now I have a different kind of cleanup problem and am looking for help.

My code registers to be notified when table data is changed. When the event triggers, it re-registers. It works fine. The problem comes when my subscribing program ends: it orphans the last subscription. When the program re-starts it subscribes as before, but now there are now two subscriptions (or three, or however many times my program is shut down). As an Admin I can run KILL QUERY NOTIFICATION SUBSCRIPTION ALL; I can even hard code this into my app as it is the only one (for now) using this instance of SS. But there must be a better way.

When I subscribe (.NET) how do I get the subscription id? Then I could just KILL that single id when my code shuts down. Specifically what code should I include in StopListener()? Thank you.



public void StartListener()

{


// starts a new thread whose sole purpose is to sleep until waked

Debug.WriteLine( "RequestNotification: StartListener" );

if( null == _listener )

{

_listener = new Thread( Listen );

_listener.Name = _threadName;

_listener.IsBackground = true; // essential!

_listener.Start();

}

}



public void StopListener()

{


Debug.WriteLine( "RequestNotification: StopListener" );

// not necessary, but good practice

_listener.Abort();

_listener = null;

Debug.WriteLine( "RequestNotification: Listener aborted..." );

}



private void Listen()

{


// infinite loop on this thread: keep listening even after

// receiving notification

while( true )

{


// connects to SqlServer queue and sleeps until a notification msg arrives

using( SqlConnection conn = new SqlConnection( _connect ) )

{


conn.Open();

Debug.WriteLine( "RequestNotification: Listen connection opened..." );

using( SqlCommand cmd = conn.CreateCommand() )

{


cmd.CommandText = "WAITFOR ( RECEIVE * FROM " + _queue + ");";

cmd.CommandTimeout = 0; // _notificationTimeout + 100;

try

{


// the thread is blocked until the waitfor event occurs.

SqlDataReader reader = cmd.ExecuteReader();

// the waitfor has triggered

while( reader.Read() )

{

// messageText = System.Text.ASCIIEncoding.ASCII.GetString( (byte[]) reader.GetValue( 13 ) ).ToString();

}

// and now we need to hand things back to the user's passed

// delegate, ensure we're back on the UI thread as well

//object[] args = { this, EventArgs.Empty };

Debug.WriteLine( "RequestNotification: Notification received." );

SqlNotificationEventArgs e = new SqlNotificationEventArgs( SqlNotificationType.Change, SqlNotificationInfo.AlreadyChanged, SqlNotificationSource.Database );

_delegate( this, e );

}

catch( SqlException )

{


// if the queue name doesn't match one in the db an exception will be thrown

throw;

}
}

}

}

}

View 2 Replies View Related

Query Notification Error

May 6, 2007

Hi All



In Work , we created a Cache component that serves a large business application, we are subscribing to almost 200 queries , the component worked quite well in the first few months of the development, but lately i am getting notification events that contain "Error" in the SqlNotificationEventArgs of the event , the "Source" value is "Client".



I have no idea what might cause this error event , we are close to "go live" with our product and we cannot depend on the Query Notification mechanism until this problem is solved.



Can it be a DataBase problem? Application Problem?



Thanks in advance



Eden

View 4 Replies View Related

SqlDependancy OnChange Event Problem

Feb 7, 2007

I've wrote a component that take advantage of the query notification macjanizm, i use this component in a web service , and its working great, with a little problem , i have imporsonation enabled in my web service and a user and password is set in the identity node in web.config , the impersonation is working great and the web service is running under the user name i've set in the web.config , but, when i change a table in the database and the change event is raised in my application the user name is no more the user in the web.config...The user is now ASPNET ....



How can i solve this problem of user name change?





Thanks in advance ,

Eden

View 1 Replies View Related

SqlDependancy OnChange Event Triggers Over And Over Again

Mar 29, 2007

I have an sql dependancy setup on a particular table that is not updated all that often. When I load my application that has the dependancy code in it, the onChange event of the SqlDependancy fires over and over again non stop. I am positive I am not updating the information in the table I am querying so I can not figure out why it would do that. But I bet one of you knows! If you need code I can supply it and if you need anything else let me know. Thanks in advance.

View 9 Replies View Related

Query Notification Not Fire All Subscriptions...

Jan 22, 2007

Hello all,

We have encountered a weird problem; we have an application that registers to several queries for notification.

For several weeks everything worked fine, any change to any query result in the database triggered the notification event, but since yesterday the mystery began€¦ since yesterday not all changes triggers events , changing one table raise the notification event, changing the other doesn€™t , all seems fine in the database , the application reports that all queries were registered successfully , in the subscription view in the database we can see that all the queries that the application subscribed to are present€¦

What can be the problem? Is it something in the database? Can it be a problem in our application, please keep in mind that everything worked until yesterday€¦



Thanks,

Eden

View 4 Replies View Related

Query Notification - Checking Permissions

Jul 17, 2007

Hi all,



I am looking at replacing a polled system with Query Notification. However when I create the SqlDependency I need to be sure I have the correct permissions. I check the SqlClientPermissions via the Demand() method, but also want to ensure I have the correct DB permission given my current connection string. As I understand it I need to have the following permissions:



CREATE PROCEDURE, QUEUE, and SERVICE permissions
SUBSCRIBE QUERY NOTIFICATIONS
SELECT on underlying tables
RECEIVE on QueryNotificationErrorsQueue



I check most of these via the 'has_perms_by_name' function, but cannot find the correct syntax to check for RECEIVE on QueryNotificationErrorsQueue. I would also love to find a way to do this via SMO instead of issuing SQl commands. Also am I missing any checks ....



Finally, I have also run into the problem whereby SQL issues the following error:



The activated proc [dbo].[SqlQueryNotificationStoredProcedure-1fd90369-7781-4bad-a1b7-e1b56e328374] running on queue ImlHostDB.dbo.SqlQueryNotificationService-1fd90369-7781-4bad-a1b7-e1b56e328374 output the following: 'Could not obtain information about Windows NT group/user 'EMEADyerN', error code 0x54b.'



I ran into this issue when I bought my machine out of sleep mode with it no longer connected to the network. Is their no way to get a error notification. In this situation I will just stop seeing notification and without looing at the ErrorLog believe their is nothing wrong.



Many Thanks, Nick





View 5 Replies View Related

Query Notification - Setup Problems

Jul 16, 2007

Hi Guys,



I'm having some problems setting up a SQL Server 2005 Query Notification application. I've only recently moved from SQL Server 2000 so 2005 is still a little alien to me!



I've followed example found on the internet in the following steps:



1.

ALTER DATABASE <dbname> SET ENABLE_BROKER



2.

GRANT CREATE PROCEDURE TO <user>

GRANT CREATE QUEUE TO <user>

GRANT CREATE SERVICE TO <user>

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO <user>

GRANT RECEIVE ON QueryNotificationErrorsQueue TO <user>



3.

ALTER DATABASE <dbname> SET TRUSTWORTHY ON



The application developers have also followed the same example setting up SQL cache and the connection code. When they start the application I can see the connection in the activity monitor but it has a status of SUSPENDED. I've also checked the view:

SELECT * FROM sys.dm_qn_subscriptions



There are no subscriptions setup I can however see that there is a new SP created. I tried to creating master keys as well but I'm not sure what the reasoning behind this is.



Is there anything else I need to take into consideration or check? When I change the data which they use for their select statement SQL profiler doesn't register anything (except the update). I have however seen this:



exec sp_executesql N'END CONVERSATION @p1; BEGIN CONVERSATION TIMER (''69e2c786-9d33-dc11-a751-0050568146e8'') TIMEOUT = 120; WAITFOR(RECEIVE TOP (1) message_type_name,
conversation_handle, cast(message_body AS XML) as message_body from [SqlQueryNotificationService-5fb25d04-6ef6-47e6-9406-854f15e16eb7]), TIMEOUT @p2;',N'@p2 int,@p1
uniqueidentifier',@p2=60000,@p1='BD98F6B4-A133-DC11-A751-0050568146E8'



This occurs when they refresh the page.



Any ideas?



Cheers!



Ian









View 1 Replies View Related

SQL Server 2005 And Query Notification

Jun 9, 2006

I have been testing SQLDependency and I have a two questions;

1) When using a stored procedure to run the dependency query, using a "clean" procedure (containing nothing but a select statement), works fine. Adding try..catch (which is a part of our coding standards), results in the subscription firing immediately because of an invalid query. Is this by design? If so, how can I implement error handling.

2) How does SQLDependency handle SQL Server restarts?
I see two options:
a) The subscription is fired listing a server restart message in the related service broker queue, but as far as I can tell, SQLDependency has no way of handling these messages given the connection has been broken. (Establishing a new connection and dependency won€™t read the said messages).
b) The SQLDependency listener on the client raises an error for the connection being terminated. Can I relay on this event to recreate a connection and dependency?

Help will be appriciated
Boaz

View 3 Replies View Related

SQL Query - DATEADD Function ? Goal - Have Events @+3 Days Display Today

Feb 23, 2004

I have events which require certain things be done several days before the event and things be done several days after the event. I attempted to use the DATEADD function to subtract 3 days from the event date. The SQL Statement I created did just that, but, it displays 3 days back from today's date.

There are 2 tables:

CalendarCategories -- Table

CalCategoryID -- int field
CalCategoryName -- varchar field

CalendarEvents -- Table

CalCategoryID -- int Field
Title -- varchar Field
StartDate -- DateTime Field


I have to perform some tasks 3 days before the event. So, TODAY, I want to see a listing of those events which are scheduled for 3 days FROM NOW.

This is my current SQL Statement:
SELECT DATEADD(d,-3,StartDate) AS [Update Payoffs & Ins], Title AS [Closing Description] FROM CalendarEvents WHERE datepart(dd,StartDate)=datepart(dd,getdate()) AND datepart(mm,StartDate)=datepart(mm,getdate())

This SQL Statement takes TODAY'S events and gives them a date of February 20. See example of the results at http://www.joelwilliamslaw.com/DesktopDefault.aspx?tabid=141


This is what I have already done relative to my calendar listings:

Specific Event Types for the Current Month :

SELECT StartDate AS [Date and Time], CalCategoryName AS [Cls Type], Title AS [Closing Description] FROM CalendarEvents inner join CalendarCategories
on CalendarEvents.CalCategoryID = CalendarCategories.CalCategoryID
where (CalendarEvents.CalCategoryID = 1 OR CalendarEvents.CalCategoryID = 2 OR CalendarEvents.CalCategoryID = 3 OR CalendarEvents.CalCategoryID = 4 OR CalendarEvents.CalCategoryID = 20) AND (datepart(mm,StartDate)=datepart(mm,getdate()) AND datepart(yy,StartDate)=datepart(yy,getdate())) AND CalendarEvents.ModuleID = 360 ORDER BY StartDate ASC

Specific Event Types for the Current Day:

SELECT StartDate AS [Date and Time], CalCategoryName AS [Cls Type], Title AS [Closing Description] FROM CalendarEvents inner join CalendarCategories
on CalendarEvents.CalCategoryID = CalendarCategories.CalCategoryID
where (CalendarEvents.CalCategoryID = 1 OR CalendarEvents.CalCategoryID = 2 OR CalendarEvents.CalCategoryID = 3 OR CalendarEvents.CalCategoryID = 4 OR CalendarEvents.CalCategoryID = 20) AND (datepart(dd,StartDate)=datepart(dd,getdate()) AND datepart(mm,StartDate)=datepart(mm,getdate()) AND datepart(yy,StartDate)=datepart(yy,getdate())) AND CalendarEvents.ModuleID = 360 ORDER BY StartDate ASC

Your assistaince is much appreciated.

Joel

View 6 Replies View Related

SqlDependency OnChange Event Fires Repeatedly

Mar 27, 2008

I am using the SqlDependency to notify me of data changes in a table. However, as soon as I start it, the OnChange event fires over and over even though no data has changed.

Essentially All I want to do is be notified when records are inserted into a table. I am able to get another example to work using a Service Broker Queue and a sql query of WAITFOR ( RECEIVE CONVERT(int, message_body) AS msg FROM QueueMailReceiveQueue ) However I would prefer not to use a queue for once my messages have been read they are taken off the queue and I would rather control that manually.

Any help with getting SqlDependency to notify my app when records are added and not over and over when the data has changed would be great.

Here is my code:




Code Snippet
public partial class Form1 : Form {


public static event OnChangeEventHandler OnChange;
string _strConnString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=email_queue;Pooling=False;";
string _strSql = "SELECT email_id from email where isprocessed = 0";
private DataSet dataToWatch = null;
private SqlConnection connection = null;
private SqlCommand command = null;
SqlDependency dependency = null;
SqlDataReader sdr = null;


public Form1() {


InitializeComponent();
}

private void button1_Click(object sender, EventArgs e) {

SqlDependency.Stop(_strConnString);
SqlDependency.Start(_strConnString);
if (connection == null) {

connection = new SqlConnection(_strConnString);
connection.Open();
}
if (command == null) {

command = new SqlCommand(_strSql, connection);
}
if (dataToWatch == null) {

dataToWatch = new DataSet();
}
GetData();
}

private void GetData() {

dataToWatch.Clear();
command.Notification = null;
dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
command.CommandTimeout = 400;
using (SqlDataAdapter adapter = new SqlDataAdapter(command)) {

adapter.Fill(dataToWatch, "email");
}
}

private void dependency_OnChange(object sender, SqlNotificationEventArgs e) {

ISynchronizeInvoke i = (ISynchronizeInvoke)this;
if (i.InvokeRequired) {

OnChangeEventHandler tempDelegate = new OnChangeEventHandler(dependency_OnChange);
object[] args = { sender, e };
i.BeginInvoke(tempDelegate, args);
return;
}
dependency = (SqlDependency)sender;
dependency.OnChange -= dependency_OnChange;
this.Text = DateTime.Now.ToString();
GetData();
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e) {

SqlDependency.Stop(_strConnString);
if (connection != null) {

connection.Close();
}
}
}

View 4 Replies View Related

SiteMap Query Notification In Web Farm Scenario

Feb 11, 2007

Dear,
I have designed a SiteMap provider for SQL Server. But I am worried about the notification service of SQL Server. My SiteMap requires service broker enabled in SQL Server. When I have web farm (multiple clustered server) does the Sql Server service broker notify all the web servers? Or, it notifies only the server request?
Have anubody implement such scenario? Looking forward for your reply.
Sincere Regards,Sultan

View 1 Replies View Related

Query Notification / Server Log Error Messages

Oct 11, 2007

Two days ago I discovered that the drive on our test SqlServer2005 was full. The current Error_log had 54+ Gb (yes Gb) of records. Not only did I delete the file I restarted SS and the server.

That afternoon, I discovered that the current log had 33,678 records! I believe 33,616 of the records came from a single run of my app and set of program events. Obviously I'm doing something wrong in my Query Notification implementation and testing. And yet, when I try to to deliberately trigger the phenomenon, I can not.


Here is the head of the exported log file; the two msgs (query dialog closed and cannot drop queue) alternate thousands and thousands of times form a single test run. What is going on?! Pls help!

Date,Source,Severity,Message
10/11/2007 11:42:52,spid5s,Unknown,SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
10/11/2007 11:42:52,spid5s,Unknown,SQL Server is terminating in response to a 'stop' request from Service Control Manager. This is an informational message only. No user action is required.
10/11/2007 11:42:49,spid14s,Unknown,Service Broker manager has shut down.
10/11/2007 11:42:47,spid51,Unknown,Configuration option 'show advanced options' changed from 1 to 0. Run the RECONFIGURE statement to install.
10/11/2007 11:42:47,spid51,Unknown,Configuration option 'Agent XPs' changed from 1 to 0. Run the RECONFIGURE statement to install.
10/11/2007 11:42:47,spid51,Unknown,Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
10/11/2007 11:42:04,spid51,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid54s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid54s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid52s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid52s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid52s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid52s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid54s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid54s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid52s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid52s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid54s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'
10/11/2007 11:42:03,spid54s,Unknown,The query notification dialog on conversation handle '{72FF98A6-1478-DC11-B117-003048772A14}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8470</Code><Description>Remote service has been dropped.</Description></Error>'.
10/11/2007 11:42:03,spid52s,Unknown,The activated proc [ovs].[SqlQueryNotificationStoredProcedure-ed59bba2-19b1-42a3-9aaa-f8a76b844561] running on queue OVS_GOM_Protected.ovs.SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561 output the following: 'Cannot drop the queue 'SqlQueryNotificationService-ed59bba2-19b1-42a3-9aaa-f8a76b844561'<c/> because it does not exist or you do not have permission.'

View 2 Replies View Related

Query Notification Stops Working After 10 Minutes

Dec 29, 2006

Hi All

We built a Cache component that take advantage of the SQL Server 2005 query notification mechanism, all went well , we tested the component in a console application , and notifications kept coming for as long time as the console application ran.

When we initiate our Cache Component in our web service global.asx application start event , the query notification works for a few minutes , but if we came after 10 minutes or so , we stoped getting notifications from sql, the SQL Server queue is empty , and all is showing that there is nothing wrong on the DB side...

Our Cache component is a Singleton class , that perform all registrations ,catch the notification events and resubscribe for notifications.

What can be the problem? is our Cache component object are being collected by GC?

Does IIS disposes the SQL Connection that the Query notification uses?

We are on a crisis...

Thanks in advance.

 

 

 

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved