Giter VIP home page Giter VIP logo

monitor-table-change-with-sqltabledependency's Introduction

Monitor and receive notifications on record table change

License NuGet Badge Released SQL Server .NET .NET Core

SqlTableDependency is a high-level C# component used to audit, monitor and receive notifications on SQL Server's record table changes. For any record table change, as insert, update or delete operation, a notification containing values for the record changed is delivered to SqlTableDependency. This notification contains insert, update or delete record values.

This table record tracking change system has the advantage to avoid a select to retrieve updated table record, because the updated table values record is delivered by notification.

Get record table change

If we want get alert on record table change without paying attention to the underlying SQL Server infrastructure then SqlTableDependency's record table change notifications will do that for us. Using notifications, an application can detect table record change saving us from having to continuously re-query the database to get new values: for any record table change, SqlTableDependency's event handler get a notification containing modified table record values as well as the INSERT, UPDATE, DELETE operation type executed on database table.

As example, let's assume we are interested to receive record table changes for the following database table:

Let's start installing SqlTableDependency using:

Install-Package SqlTableDependency

We now define a C# model mapping table columns we are interested: these properties will be populated with the values resulting from any INSERT, DELETE or UPDATE record table change operation. We do not need to specify all table columns but just the ones we are interested:

public class Customer
{
 public int Id { get; set; }
 public string Name { get; set; }
 public string Surname { get; set; }
}

Model properties can have different name from table columns. We'll see later how to establish a mapping between model properties and table columns with different name.

Now create SqlTableDependency instance passing the connection string and table name (database table name is necessary only if the C# model has a name that is different from the database table name). Then create an event handler for SqlTableDependency's Changed event:

public class Program
{
 private static string _con = "data source=.; initial catalog=MyDB; integrated security=True";
   
 public static void Main()
 {
  // The mapper object is used to map model properties 
  // that do not have a corresponding table column name.
  // In case all properties of your model have same name 
  // of table columns, you can avoid to use the mapper.
  var mapper = new ModelToTableMapper<Customer>();
  mapper.AddMapping(c => c.Surname, "Second Name");
  mapper.AddMapping(c => c.Name, "First Name");

  // Here - as second parameter - we pass table name: 
  // this is necessary only if the model name is different from table name 
  // (in our case we have Customer vs Customers). 
  // If needed, you can also specifiy schema name.
  using (var dep = new SqlTableDependency<Customer>(_con, "Customers", mapper: mapper));
  {
   dep.OnChanged += Changed;
   dep.Start();

   Console.WriteLine("Press a key to exit");
   Console.ReadKey();

   dep.Stop();
  } 
 }

 public static void Changed(object sender, RecordChangedEventArgs<Customer> e)
 {
  var changedEntity = e.Entity;
      
  Console.WriteLine("DML operation: " + e.ChangeType);
  Console.WriteLine("ID: " + changedEntity.Id);
  Console.WriteLine("Name: " + changedEntity.Name);
  Console.WriteLine("Surname: " + changedEntity.Surname);
 }
}

Done! Now you are ready to receive record table change notifications:

Receive SQL server notifications GIF video

Monitor record table change examples and use cases

To see SqlTableDependency in action, check the following online long running test. Here, SqlTableDependency is tested continuously using a thread that every five seconds perform an update record table change. SqlTableDependency monitor this record table change and get a notification containing new update record table values.

Also, here are some examples of applications getting notification on record table change. After downloading the example, please remember to update SqlTableDependency nuget package:

  • Monitor table change with Blazor: This example uses .NET CORE 3.0 Blazor (server side) to create a single page application that makes real-time update of its content on database record changes.
  • Monitor table change with WPF and WCF: This example shows how to refresh a DataGrid of stock data. The grid will be updated whenever a record table change occurs. The notification event contains new values for the modified table record.
  • Monitor table change with MVC, SignalR and jQuery: This example shows how to refresh a HTML table containing stock values. The HTML table will be updated whenever a record table change occurs. Notification event contains new values for the modified table record.
  • Monitor table change with MVC, SignalR and Knockout JS: This example shows how to refresh client web browsers used to book flight tickets. Those terminals must be updated as soon as the availability change and the Web application must take the initiative of sending this information to clients instead of waiting for the client to request it.

This section reports some use case examples:

How Track record table change is done

SqlTableDependency's record change audit, provides the low-level implementation to receive database record table change notifications creating SQL Server triggers, queues and service broker that immediately notifies your application when a record table change happens.

Assuming we want to monitor the Customer table content, we create a SqlTableDependency object specifying the Customer table and the following database objects will be generated:

  • Message types
  • Contract
  • Queue
  • Service Broker
  • Trigger on table to be monitored
  • Stored procedure to clean up the created objects in case the application exits abruptly (that is, when the application terminate without disposing the SqlTableDependency object)

DatabaseObjects

Remark about record table change system

The Start(int timeOut = 120, int watchDogTimeOut = 180) method starts the listener to receive record table change notifications. The watchDogTimeOut parameter specifies the amount of time in seconds for the watch dog system.

After calling the Stop() method, record table change notifications are not longer delivered. Database objects created by SqlTableDependency will be deleted.

It is a good practice - when possible - wrap SqlTableDependency within a using statement or alternatively in a try catch block: when the application will stop, this is enough to remove the SqlTableDependency infrastructure (Trigger, Service Broker, Queue, Contract, Messages type and Stored Procedure) automatically.

In any case, when the application exits abruptly โ€“ that is by not calling the Stop() and/or Dispose() method - we need a way to cleaning up the SqlTableDependency infrastructure. The Start() method takes an optional parameter watchDogTimeOut. If there are no listeners waiting for notifications, the SqlTableDependency infrastructure will be removed after this period of time. The default value of watchDogTimeOut is 180 seconds.

There is a common scenario that could trigger the watchdog: debugging. During development, you often spend several minutes inside the debugger before you move on to the next step. Please make sure to increase watchDogTimeOut when you debug an application, otherwise you will experience an unexpected destruction of database objects in the middle of your debugging activity.

alt text Audit record table change requirements and info

  • SQL Server 2008 R2 or latest versions (please see note about Compatibility Level and Database Version).
  • .NET Framewrok 4.5.1 or latest versions / .NET CORE 2.0 or latest versions.
  • When database connection has been lost, there is no way to re-connect SqlTableDependency instance to its queue. A new instance of SqlTableDependency is needed to get record table change notifications again.
  • Windows service using SqlTableDependency must not goes to SLEEP mode or IDLE state. Sleep mode blocks SqlTableDependency code and this result in running the database watch dog that drops all SqlTableDependency's db objects (please see https://stackoverflow.com/questions/6302185/how-to-prevent-windows-from-entering-idle-state).
  • Database Backup and Restore: restoring SqlTableDependency's db objects, it does not work.

To use notifications, you must be sure to enable Service Broker for the database. To do this run the SQL command:

ALTER DATABASE MyDatabase SET ENABLE_BROKER

In case the user specified in the connection string is not database Administrator, db owner or neither has db_owner role, please make sure to GRANT the following permissions to your login user:

  • ALTER
  • CONNECT
  • CONTROL
  • CREATE CONTRACT
  • CREATE MESSAGE TYPE
  • CREATE PROCEDURE
  • CREATE QUEUE
  • CREATE SERVICE
  • EXECUTE
  • SELECT
  • SUBSCRIBE QUERY NOTIFICATIONS
  • VIEW DATABASE STATE
  • VIEW DEFINITION

It is possible skip permissions test done by SqlTableDependency setting executeUserPermissionCheck constructor parameter to false. Nevertheless a SQL server exception will be thrown if user have not sufficient permissions.

In case you specify SqlTableDependency's QueueExecuteAs property (default value is "SELF"), can also be necessary set TRUSTWORTHY database property using:

ALTER DATABASE MyDatabase SET TRUSTWORTHY ON

alt text Note about Compatibility Level and Database Version for tracking record changes

Please, check how David Green solved this problem: https://github.com/christiandelbianco/monitor-table-change-with-sqltabledependency/wiki/Contributors

From time to time, I receive bugs reporting issue like "I not detect/receive any record table change notification". Assuming that you are using a logic with enough grants, one of the possible cause of this missing table record change notification, is due to Database compatibility version. Even if your SQL Server instance is SQL Server 2008 R2 or latest versions, can be that your Databasehas been created using an old SQL Server version, for example SQL Server 2005. To reproduce this issue, you can download Northwind.mdf file and then attach it to your SQL Server 2008 R2 (or greater) instance. Running SqlTableDependency against it, no exception is raised as well as no notification on record table change is detected.

In order to discover your database compatibility version, you can use the following SQL script (see details on http://jongurgul.com/blog/database-created-version-internal-database-version-dbi_createversion/).

USE <your db>

DECLARE @DBINFO TABLE ([ParentObject] VARCHAR(60),[Object] VARCHAR(60),[Field] VARCHAR(30),[VALUE] VARCHAR(4000))
INSERT INTO @DBINFO
EXECUTE sp_executesql N'DBCC DBINFO WITH TABLERESULTS'
SELECT [Field]
,[VALUE]
,CASE
WHEN [VALUE] = 515 THEN 'SQL 7'
WHEN [VALUE] = 539 THEN 'SQL 2000'
WHEN [VALUE] IN (611,612) THEN 'SQL 2005'
WHEN [VALUE] = 655 THEN 'SQL 2008'
WHEN [VALUE] = 661 THEN 'SQL 2008R2'
WHEN [VALUE] = 706 THEN 'SQL 2012'
WHEN [VALUE] = 782 THEN 'SQL 2014'
WHEN [VALUE] = 852 THEN 'SQL 2016'
WHEN [VALUE] > 852 THEN '> SQL 2016'
ELSE '?'
END [SQLVersion]
FROM @DBINFO
WHERE [Field] IN ('dbi_createversion','dbi_version')

Executing this script on Northwind database you get:

Executing this script on DB created by SQL Server 2008 R2 instance (database name TableDependencyDB), the result is:

So, even if your SQL Server instance is 2008 R2 or greater, DB compatibility level (VALUE column) is fundamental to receive record table change notifications.

Not supported SQL Server table column types

Following SQL Server columns types are not supported by SqlTableDepdency:

  • XML
  • IMAGE
  • TEXT/NTEXT
  • STRUCTURED
  • GEOGRAPHY
  • GEOMETRY
  • HIERARCHYID
  • SQL_VARIANT

Limitations

SqlTableDependency does not consider an empty string different from a string containing only spaces; example: '' and ' ' are considered eguals. This means that in there is case of update from '' to ' ' - and vice versa - this change it will not be notified. Same is true for NULL and empty string. Please check https://support.microsoft.com/en-us/help/316626/inf-how-sql-server-compares-strings-with-trailing-spaces.

SqlTableDependency works with traditional disk-based tables: it does not works with In-Memory OLTP tables.

Difference between SqlTableDependency and SqlDependency from ADO.NET

Functionalities comparison between Microsoft ADO.NET SqlDependency and SqlTableDependency:

Functionality SqlTableDependecy SqlDependency
View
Join multiple tables
Where
Generic
Notification containing updated values
Notification containing old values
Notification only on insert
Notification only on update
Notification only on delete
Notification only when specific column is changes
Useful link and tips
Contributors

Open-source software (OSS) is a type of computer software in which source code is released under a license in which the copyright holder grants users the rights to study, change, and distribute the software to anyone and for any purpose.Open-source software may be developed in a collaborative public manner. Please, feel free to help and contribute with this project adding your comments, issues or bugs found as well as proposing fix and enhancements. See contributors.

monitor-table-change-with-sqltabledependency's People

Contributors

christiandelbianco avatar flogex avatar igitur avatar nilkamal avatar pwlsjk avatar sayuj avatar tobaloidee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monitor-table-change-with-sqltabledependency's Issues

No support for .Net Core

I get this error when I try to install this nuget package in my .Net Core project:

Package SqlTableDependency 6.1.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package SqlTableDependency 6.1.0 supports: net (.NETFramework,Version=v0.0)

Are there any plans for this package to support .Net Core?

Incorrect syntax near 'POISON_MESSAGE_HANDLING'.

Hi
I get the error bellow when the SqlTableDependency start method is launched

**An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in the user code

Additional Information: Incorrect syntax near 'POISON_MESSAGE_HANDLING'.**

can you help me ?

Support for SQL Server 2008 R2

Hi Christian,

I see on your repo that the version for SQL Server must be at least 2012.
Can you confirm it does not work on SQL Server 2008 R2?
If it does not work, could you be so kind to detail the reasons behind ?

Kind regards!

The conversation handle "A705917C-4762-E711-9447-000C29C3FCF0" is not found

I have started SQL table dependency in a table. I gave all the permission to database listed in your document. After some times ,may be in idle condition it is giving status as "Waiting for notification" .

When I change in table (inserting new record), status is not changing (From waiting for notification) and gives error as "The conversation handle "A705917C-4762-E711-9447-000C29C3FCF0" is not found."

Can you please help me to fix this issue?

Exception when a table name is keyword

I have a client with a table named "Transaction.Header" and "Transaction.Item". I create my dependency with
_tableDependency = new SqlTableDependency(ConnectionString, TableName);
_tableDependency.Start();

Where TableName is "Transaction.Header" or "Transaction.Item". The exception occurs on Start()
System.Data.SqlClient.SqlException, Incorrect syntax near the keyword 'Transaction'.

Note I've tried the string "[Transaction].[Header]" and that also does not work. I see in your code you remove the []. Possibly they should not be removed?

Performance concerns using SqlTableDependency in a Windows Form application

Hello,

We developed a Windows Forms booking system some years ago.
This application manages booking of hotel rooms associated with tours organized by our customer.
While making a reservation, a map of all free rooms is shown to the user.
We developed the system so that while a user is booking a room for a certain tour, other users are not allowed to book on the same tour.
This is to avoid that two users occupy the same room.

This was acceptable when the system was used by emplyees only.
Now we're opening the booking system to Internet, using MVC, while keeping the Windows Forms application for reservations made by employees (WF App has some advanced functions not available to customers).

In order to manage concurrency, we were evaluating SqlTableDependency, so that both WF App users and MVC users are notified as soon as a room gets occupied.

But we are wondering if this component can be safely used on many (10-15) windows clients monitoring the same table at the same time.

Thank you!

ASP.NET

Hi,

I created an asp.net application (w/ SignalR) that monitors a table. It all works fine, but in production, I see that the database triggers etc get cleared after some time. This may be related to the fact that IIS automatically suspends worker-processes after some idle time.

Do you have a suggestion which configuration / settings can be used in order to ensure that the SqlTableDependency will remain 'active', or resume?

Thanks,
Erik

Problem with double type column

I have a problem with a double type column (this column stores a datetime as an SQL Format), when the insert was reported, the value was truncate to only 2 decimal digits.

Table name not found for tables with multiple period (.) characters

I'm having trouble with using the sqltabledependency for tables that have at least one period (.) character on them i.e. "[dbo].[Stream.Users]". It seems that you're splitting the table name and only getting the string on the first index of the split array as the table name based on the code.

Old values when update

Is there some solution provide me to get the old values when ChangeType is Update?
I need to know which column update from what value.

Azure 'sys.login_token' is not accessible

Hi have you tried this with Azure? When I try I initialize the TableDependency object I get the error below, looks like 'sys.login_token' is not accessible from AzureSQL.

{System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'sys.login_token'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at TableDependency.SqlClient.SqlTableDependency1.CheckIfUserHasPermissions(String connectionString)
at TableDependency.TableDependency1..ctor(String connectionString, String tableName, IModelToTableMapper1 mapper, IUpdateOfModel`1 updateOf, ITableDependencyFilter filter, DmlTriggerType dmlTriggerType, Boolean executeUserPermissionCheck)
at Server.Hubs.Challenge.DatabaseSubscriptions

edit: Use with existing EF Core 2.0 DbContext

Hey Christian,
I really love how this looks. I think I got a proj with all the current versions, but I get this error from PM:

Warning NU1701 Package 'SqlTableDependency 6.1.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

Also wondering on an approach to use the connection string or connection from existing DbContext? I pull the connection string from my config:

using (var dep = new SqlTableDependency<DwsFileExt>(config.GetConnectionString("DwsConnection"), "DwsFiles", mapper))
And I get an Exception message in my OutPut:

Exception thrown: 'TableDependency.SqlClient.Exceptions.UserWithNoPermissionException' in TableDependency.SqlClient.dll
An exception of type 'TableDependency.SqlClient.Exceptions.UserWithNoPermissionException' occurred in TableDependency.SqlClient.dll but was not handled in user code
User without permissions.

I'm working on implementing in a EF Repository and will happy share my results if I can get it all working.

Thanks,
Eric

Support for SQL Geometry and Geography change notification

Hi

I am using sqltabledependency to monitor change in my table and it works nicely apart from one column. It is of type sys.geometry and holds lat/lon points. When I update the column with a new point there is no change notification. I am trying to report on real-time location change.

I wonder if that is something you would consider supporting please?

Thanks

Error - User with no 'CONNECT' permission.

Hi,

I am tried to use SqlTableDependency approach. But i am getting this error.

at TableDependency.SqlClient.SqlTableDependency1.CheckIfUserHasPermissions(String connectionString) at TableDependency.TableDependency1..ctor(String connectionString, String tableName, IModelToTableMapper1 mapper, IUpdateOfModel1 updateOf, ITableDependencyFilter filter, DmlTriggerType dmlTriggerType, Boolean executeUserPermissionCheck)
at TableDependency.SqlClient.SqlTableDependency1..ctor(String connectionString, String tableName, IModelToTableMapper1 mapper, IUpdateOfModel`1 updateOf, ITableDependencyFilter filter, DmlTriggerType notifyOn, Boolean executeUserPermissionCheck)
at WindowsFormsApplicationTrack.Form1.Form1_Load(Object sender, EventArgs e) in

Can you help on this.

Thanks,
Niraj

Subscribe to an existing subscription

Hi Christian,

I just wondered what the rationale was when deciding to force tearing the subscription setup down (i.e. the SqlTableDependency infrastructure such as Trigger, Service Broker service, the queue, etc.), whenever application stops (either gracefully or crashing).

Would it be at all possible to leave infrastructure intact thus subscribe back to it on next startup?
That way subscriber would not miss out any messages.

Many thanks

Minimal SQL version requirement.

I'm getting this error: "Incorrect syntax near 'POISON_MESSAGE_HANDLING'."
We are using SQL 2008 (no R2).

Is there a minimal SQL version requirement?

Support .Net Core

Hi Christian,

Any possibility that that there is Nuget package with .Net Core?

Doe is support configuring to multiple table to watch instead of Type T . One at a time.

Timeout expired

Hi Christien,

I've following error on OnError event handler. Can use please sort this out ?

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

Encountered 2 Issues at Client side

I encountered two issue when try this solution.

  1. Client has not responded after sometimes even table has changes (insert/update/delete). I need to stop the application pool at the web service server then restart, then the client will be working fine again.
  2. Client program exit with code -1 every time when i stop the client program running.

Can you please help to advise where is going wrong? I followed the code in your website and has minor modification (eg table, connection string, etc). And also I change to simple window application instead of WPF application by writing the changes to the Debug output.

Thanks in advance! :)

p/s: wcf code and client code are attached as well.

wcf_client.zip

Exception when Schema name is a keyword

I'm getting an exception when using this when our Schema is keyword.

The Schema is Transaction and the Table is Item...so [Transaction].[Item].

Here is the model:
[Table("Item", Schema = "Transaction")]
public class TransactionItem
{
public Guid TransactionItemId { get; set; }
public string Description { get; set; }
}

TearDown not available

Hello,

I am trying to set the "teardown" to false so that objects are not removed every time service stops.
Does SqlTabledependancy support teardown functionality. It was mentioned in the release notes version 5 as a new feature. I looked at the code and don't see a constructor for tabledepenndancy which takes teardown as parameter

SqlTransaction problem after some time

Good morning, we are using SqlTableDependency into an always running Windows Service like a "notifications centralized service"; after about two days of always running we get a sql transaction exception, i logged also the SqlTableDependency status change:

[21:02:33] Status changed: STOPDUETOERROR
[21:02:33] Error message: TableDependency stopped working
exception: System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.
at System.Data.SqlClient.SqlTransaction.ZombieCheck()
at System.Data.SqlClient.SqlTransaction.Rollback()
at TableDependency.SqlClient.SqlTableDependency`1.d__63.MoveNext()

Is maybe a sql transaction timeout problem or something like that in the sql server configuration?

Thanks very much in advance

Teardown Functionality

I noticed that in release Release 5.0.0.0 the ability to prevent the teardown of database objects was added, however this feature seems to be gone in the latest release.

Is there any documentation on how to use this feature? Or was this feature removed in a later version and no longer supported now?

Thanks heaps!

Inbound disconnects not cleaned up

Hi!

I'm using your component for a while now and I noticed that inbound disconnects aren't cleaned up, which slowed down my SQL server almost to a grinding halt (+600.000 half open connections) I guess this has todo with the fact that the conversations aren't ended in a proper manner. When I took a look at the generated triggers a couple of things got my attention...

  1. You don't use any transactions when sending messages
  2. END CONVERSATION doesn't include WITH CLEANUP

I guess that the latter is the culprit.

TIA
Bert

SqlTableDependencyFilter don't use Custom Mapping

i have a column in database: "COM_TIME" and in model : "ComTime"

then use Custom Mapper

var mapper = new ModelToTableMapper<MyEvent>();
mapper.AddMapping(c => c.ComTime, "COM_TIME");

//Using SqlTableDependencyFilter
var dt = DateTime.Now;
Expression<Func<MyEvent, bool>> expression = p => p.ComTime == dt;
ITableDependencyFilter whereCondition = new SqlTableDependencyFilter<MyEvent>(expression);

it don't work ...

and i found error in sql profiler

CREATE TRIGGER [tr_dbo_SHIJIAN_e1647094-2b4a-44e6-9630-2ce4177d3f3d] ON [dbo].[SHIJIAN] AFTER update AS 
..........
 a WHERE ([ComTime] = '2018-04-24T03:55:47')
//there is ComTime and not COM_TIME ....

Nullable types in model class

hi,
I get this message onError
Object of type 'System.Int32' cannot be converted to type System.Nullable`1[ .....MY ENUM TYPE...... ]'.

here is the stacktrace:
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at System.Reflection.PropertyInfo.SetValue(Object obj, Object value)
at TableDependency.EventArgs.RecordChangedEventArgs1.MaterializeEntity(List1 messages, IModelToTableMapper1 mapper) at TableDependency.EventArgs.RecordChangedEventArgs1..ctor(MessagesBag messagesBag, IModelToTableMapper1 mapper, IEnumerable1 userInterestedColumns, String server, String database, String sender, CultureInfo cultureInfo)
at TableDependency.SqlClient.EventArgs.SqlRecordChangedEventArgs1..ctor(MessagesBag messagesBag, IModelToTableMapper1 mapper, IEnumerable1 userInterestedColumns, String server, String database, String sender, CultureInfo cultureInfo) at TableDependency.SqlClient.SqlTableDependency1.GetRecordChangedEventArgs(MessagesBag messagesBag)
at TableDependency.TableDependency1.NotifyListenersAboutChange(Delegate[] changeSubscribedList, MessagesBag messagesBag) at TableDependency.SqlClient.SqlTableDependency1.d__63.MoveNext()

reduce amount of time before deleting create objects

is there a configuration to specify amount of time before execution of cleanup SP.
the time out is a bit problematic because in some cases if the receiver application is down, detecting that might be impossible for database code.

How to mock SqlTableDepndency integration in unit test

Hi
I am using SqlTableDepndency in my code to monitor a table. Is there a way to mock SqlTableDepndency in my unit test code or the integration tests are the only way to test the code?
Could you please suggest.

Thanks
Rupendra

Hello, long time to say hello_my free customer reported he cannot receive notification any more after one day.

You might remember me in CodePlex as a Korean programmer(Kay Lee) with non-software related major.

In these days, Winter Olympic 2018 PyeongChang, Korea is taking place and hope your country's excellent achievements !

One of my free customer reported that suddenly, without any error message, he cannot receive notification any more from a few days ago after 2 other applications were updated as he remembers.

As you might know, it's very difficult to ask informations to some customers.

With very limited information like there was no error message, I assume the local SQL server was shut downed abnormally and some dependency objects were not removed automatically and interfering normal notification.

What I'd like to know are,

When dependency objects are abnormally existing after abnormal shut down, (after turning off the computer(SQL server) and turning on at next day), what if SQLTableDependency is started and terminated normally? the previous, abnormally existing dependency objects will be removed automatically together?
(My customers turn on and off their computer(SQL server) everday.)

Do the dependency objects have unique fingerprint in their name so that I can remove exact dependency objects only, not other objects by other applications?

Kind let me know the unique fingerprint if exists,

or I do appreciate if you provide the SQL code to remove dependency objects so that I can remove previously existing dependency objects for sure before customers start my application.
(Please kindly understand again that I'm a low level programmer with non-software related major.)

We're just finishing Lunar New Year Holidays and I'll try my best to communicate with the customer and check with various indirect ways like another SQL table and so on.

Sorry, I'm always too talkative, eager to solve my problem but sure it's very easy to answer.
(Many of my customers are still using SQL 2005, 2008, therefore, I must stay with old version of SQLTableDependency like 5.x.x.x)
(and my customers don't know about programming, software, SQL)

Always thank you so much for your excellent SQLTableDependency !

Sincerely,
Kay Lee.

Change not fire after a day

Hi, I am using sqlTableDependency in a windows service. After a day of working properly, the changes in the table that I configured does not fire the event. Do you now the cause and how to fix it?
Regards

MAX_QUEUE_READERS

By default the parameter MAX_QUEUE_READERS = 1 on the Service Broker que. Is there a way to set this value from C# code for the sqltabledependency ?

What happened to oracletabledependency?

Hi Christian,

we cannot find anymore the oracletabledependency - seems to be deleted everywhere. Could you please let me know why - any major issues you encountered with it?

Thanks in advance

SQLTableDependency 6.2.0 not working with SqlTableDependencyFilter 1.2.0

Hi. Have following compiler error on SqlTableDependencyFilter constructor:
The type 'IModelToTableMapper<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'TableDependency, Version=5.0.0.0, Culture=neutral, PublicKeyToken=997305cc1a8bb802'.
When using version SQLTableDependency 6.1.0 no errors.
P.S. I have 2 questions (please forgive me if this is not a right place to ask):

  1. How to configure IIS hosting WCF that uses SQLTableDependency? Perhaps set idle timeout to 0 and schedule app pool recycle to happen each night?
  2. Is it possible to use SQLTableDependency on db being automatically backed up every night? Did not understand related remark completely.

Issue starting service with SQL 2008 (none R2)

Hi, I'm having an issue trying to implement this with an MVC application against a SQL 2008 database. However it looks like the command/hint POISON_MESSAGE_HANDLING ( [ STATUS = { ON | OFF } ) is not supported on this version.

When the application tries to register the dependency it fails due to incorrect syntax. Is there anyway I can specify a parameter to exclude the poison message hint from the Queue create statement?

P.S. This is a great library, fantastic work!!

Many Thanks
Regards
Adam

Attach to existing queues

Maybe my application crashs and because of the "WatchDogTimeout" the queues are remaining on SQL Server. Chnages to table are still logged to that Queues. It is now somehow possible to attach to an existing queue created by SQLTableDependency instead of creating a new one each time "Start" method is called?

DISCONNECTED_INBOUND

Is there a way to clean up the que status after messages have been processed by sqltabledependency? The following query shows the conversation state as DISCONNECTED_INBOUND for all messages, and it stays that way until the .Net program is terminated:

select lifetime, state_desc, security_timestamp from sys.conversation_endpoints;

Queue containing a message type not expected

Hi,
Every now-and-then I get the following error (in the OnError event).
Do you either have an idea where this comes from, or a suggestion where I can start debugging?
Thanks,
Erik

Queue containing a message type not expected [http://schemas.microsoft.com/SQL/ServiceBroker/DialogTimer].
Stacktrace: at TableDependency.Messages.MessagesBag.AddMessage(Message message)
atTableDependency.SqlClient.SqlTableDependency1.<>c__DisplayClass63_0.<WaitForNotifications>b__0(Message m) at System.Collections.Generic.List1.ForEach(Action1 action) at TableDependency.SqlClient.SqlTableDependency1.d__63.MoveNext()

POISON_MESSAGE_HANDLING (STATUS = OFF)

When creating a queue in MSSQL2008 (non-r2), that parameter is causing an error:

SqlException: Incorrect syntax near 'POISON_MESSAGE_HANDLING'.
Incorrect syntax near ')'.

From a little bit of digging it looks like that was not added until R2.

SqlTableDependency on Views

Hey Christian,
I'm pretty new to SQL Server and databases in general.
I was wondering if it is possible to get SqlTableDependency to work with views instead of tables only. Currently it throws a TableWithNoColumnsException if I try this out.
So do the triggers and the notification pipeline theoretically work with Views?

On Change not getting fired after some time

After adding data in the monitored table, change in data is reflected in the event handler. But, after time of 2- 3 hrs, it stops working. I think problem might be due to lock on queue due to activation procedure. No data change is received, even though I add records on server side table. I can see queue filled with records but no change at client side. It keeps saying
Running waitfor command
after 2 mins timeout.
Can you help me with this? It is really necessary.

SqlException Invalid object name

hi,
On call of Start() i get this error
Invalid object name 'dbo_Customers_94173d13-e99c-48ad-9084-bdf2cfb80e79'.
Invalid object name 'dbo_Customers_94173d13-e99c-48ad-9084-bdf2cfb80e79'

I followed the working example and im stuck here for days! Please help thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.