I am new to SQL Server. I need track the Data Changes in Database Table inside the Microsoft SQL Server Management Studio.If any Data insertion,Deletion and modification done..in Table ,the WCF service should receive notifications from SQL Server 2012 Database.
Is this possible to send instant notifications of Data Table from SQL server to WCF Service?
Done's and Studied:-
I am already refer some websites. I have an Idea about Change Data Capture and Change Tracking procedure in SQL Server.Then i were followed the Change Data Capture Procedure to Track the Data in SQL Server.Then i look over some information about Jobs in SQL Server Data Agent.With the help of jobs,possible to automate a query execution in sql server with a time interval?
Then i am created a Database in SQL server using DML and enabled the Change Data Capture Feature for Database and Table Level,specified number of Columns!
My New Database:-
CREATE DATABASE Testcdc_feature
GO
Use Testcdc_feature;
GO
CREATE TABLE dbo.one(
Name varchar(100),
Id int,
Designation varchar(100),
Salary int,
);
Enabled Change Data Capture Feature for Database:-
use Testcdc_feature;
GO
-- enable CDC on the database
EXEC sys.sp_cdc_enable_db;
GO
Enabled CDC Feature for The Table and Specified Columns:-
USE Testcdc_feature;
GO
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'one',
@role_name = NULL, -- Role gating not enabled
@filegroup_name = N'PRIMARY', -- should consider writing audit date to separate filegroup
@captured_column_list = N'Name,Id,Designation,Salary';
GO
Inserted Values to the Table Columns:-
USE Testcdc_feature;
GO
SET NOCOUNT ON;
INSERT INTO dbo.one VALUES(
'thirunavukkarasu',2345,'TeamLeader',12000000
);
INSERT INTO dbo.one VALUES(
'Selva',3456,'Developer',30000);
INSERT INTO dbo.one VALUES(
'John',9876,'Application Tester',45000
);
INSERT INTO dbo.one VALUES(
'Anand',56789,'Developer',56000
);
INSERT INTO dbo.one VALUES(
'Priya',6709,'Developer',78000
);
INSERT INTO dbo.one VALUES(
'Swetha',8907,'Developer',100000
);
For Check the Data Changes the query is written as below(DEMO):-
USE Testcdc_feature;
GO
DECLARE @from_lsn binary(10), @to_lsn binary(10)
SET @from_lsn = sys.fn_cdc_get_min_lsn('dbo_one')
SET @to_lsn = sys.fn_cdc_get_max_lsn()
SELECT
CT.__$start_lsn,
CT.__$operation,
CASE CT.__$operation
WHEN 1 THEN 'Delete'
WHEN 2 THEN 'Insert'
WHEN 3 THEN 'Update - Pre'
WHEN 4 THEN 'Update - Post'
END AS Operation,
CT.*,
LSN.tran_begin_time,
LSN.tran_end_time,
LSN.tran_id
FROM
cdc.fn_cdc_get_all_changes_dbo_one
(@from_lsn, @to_lsn, N'all update old') AS CT INNER JOIN
cdc.lsn_time_mapping AS LSN ON CT.__$start_lsn = LSN.start_lsn
GO
When Executing the Last Query i got output as below
I need to automate the last Query (Demo) for a time interval and send it results as instant notifications of Data modifications from SQL server to WCF Service?
The WCF Should Receive the Insertion,Modification and Deletion of Data From SQL server.is this possible?
My Question:-
1.How to automate a query execution with a time interval in MS SQL Server 2012?
2.How to send the automated query results into wcf service?
How do i achieve this? Could anyone provide me a idea or solution? It Might me more Helpful!