I use С# Express with Entity Framework. And not very good in SQL Server scripting.
So, I have this table
CREATE TABLE DataTable
(
Id INT NOT NULL ,
Value VARCHAR(20) NULL ,
Author ??????????? NOT NULL ,
CreateTime DATETIME NOT NULL ,
CONSTRAINT PK_DataTable PRIMARY KEY CLUSTERED (num ASC)
ON [PRIMARY]
)
Tell me please, how to write current Server user as author of data commit to my table.
Users enter through a local network in SQL Serve authorization mode.
It should be pretty transparently for c# programmer, and it should be handle on server side.
This would be a great place for a trigger. Database triggers are often used for logging operations such as the one you’re describing. In the trigger simply include the current user in your insert data.
There is a complete sample here.