Sql-server – Change Data Capture in a services environment

change-data-capturesql serversql-server-2012

Change Data Capture looks to be exactly what I need… Except.

All of my database actions come from users that system accounts. We have WCF service that is called by an application. The WCF Service does the authorization for the call, then the system account that the WCF Service runs as makes the needed call to the database.

This allows us to tightly control permissions on the SQL Server.

Because of this, Change Data Capture is only going to be recording that generic user's information.

But I need to know the actual user that initiated the WCF Call.

Is there a way to plug in an alternate user name for Change Data Capture? Or another way to get Column level logging of who made a change and when?

Best Answer

So, after a bit of thought, I realized that I can just treat my User Information as another piece of data.

So I can add to each table a "ChangedBy" and a "ChangedWhen" column. Whenever my service updates a record, it will update the ChangedBy and ChangedWhen. Then in the Change Data Capture history, the changes include needed data.