Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

SqlDependency.OnChange fires with Sql statement but not calling a stored procedure

$
0
0

Hi all,

I don't understand why SqlDependency fires changes on DataBase if I specify a Sql stamente in the SqlCommand, but not if I specify a stored procedure.

My code:

CacheItemPolicy _policy = new CacheItemPolicy();
SqlChangeMonitor _monitor;
SqlDependency _dependency;

if (_connection.State == ConnectionState.Closed) _connection.Open();

/* This works! */
//SqlCommand _command = new SqlCommand("SELECT[LAST_UPDATE] FROM [dbo].[MY_TABLE] WHERE[ID] = " + _myId, _connection);

/* This NOT works! */
SqlCommand _command = new SqlCommand("[CACHE_CONTROLLER]" , _connection);
_command.CommandType = CommandType.StoredProcedure;
_command.Parameters.Add("@ID",SqlDbType.Int,4).Value= _myId;

_dependency = new SqlDependency(_command);
_monitor = new SqlChangeMonitor(_dependency);
_dependency.OnChange += _dependency_OnChange;

_policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(600.0);

_policy.ChangeMonitors.Add(_monitor);
_policy.UpdateCallback = CacheUpdateCallback;

_cache.Set(key, elemento, _policy);

_command.ExecuteNonQuery();

The stored procedure:

alter proc [dbo].[CACHE_CONTROLLER]
@ID INT
as

SELECT [dbo].[MY_TABLE].[LAST_UPDATE] FROM [dbo].[MY_TABLE] WHERE [dbo].[MY_TABLE].[ID] = @ID

With the Sql statement bot UpdateCallback and OnChange are fired, using the stored procedure neither one or the other.

The stored contains only one statement as suggested in other posts, I ddon't use NOCOUNT clause...

Any idea?




Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>