Domanda

I have 2 applications, one to add in database, and the other to watch any changes in database,

How can i track any changes in db ( new record, Change of existing one, deleting), Is there any class like system watcher to watch Database Table?

i searched and found SQL Dependency Class, but i don't know whether it is suitable to my scenario or not.

Thanks in advance,

È stato utile?

Soluzione

You could use a trigger, to check the INSERT, UPDATE or DELETE queries they are executed in your instance.

Furthermore, SQL Server has a great tool, SQL Server Profiler. You can use it to connect to your instance and listen to every query and action.

This SO question maybe could help you.

Altri suggerimenti

I dont recommend to go for triggers for this scenario, as it will be an extra burden.

But there are 2 options

1). Microsoft SQL Server - Change Data Capture (CDC) - here unfortunately this is NOT available in standard version. but you can find in Enterprise, Developer, and Evaluation editions

2). CodePlex-StandardCDC here

3). Change Tracking (CT) can be an option Please refer enter link description here

Use an Open-Source class SqlDependencyEx. It is pretty easy to configure and use:

int changesReceived = 0;
using (SqlDependencyEx sqlDependency = new SqlDependencyEx(
          TEST_CONNECTION_STRING, TEST_DATABASE_NAME, TEST_TABLE_NAME)) 
{
    sqlDependency.TableChanged += (o, e) => changesReceived++;
    sqlDependency.Start();

    // Make table changes.
    MakeTableInsertDeleteChanges(changesCount);

    // Wait a little bit to receive all changes.
    Thread.Sleep(1000);
}

Assert.AreEqual(changesCount, changesReceived);

Hope this helps.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top