First you need to create a trigger application in visual studios.
File -> new -> project -> Database -> select Visual C # CLR database project.
He will offer you to connect to the database. After that, make sure that the trigger application listens to the record in any table (you can learn more about the CLR application in visual studios here ).
from the above steps, add a trigger. your method should look like this:
[Microsoft.SqlServer.Server.SqlTrigger(Name = "GetTransaction", Target = "EvnLog", Event = "FOR INSERT")] public static void GetTransaction() { SqlCommand command; SqlTriggerContext triggerContext = SqlContext.TriggerContext; SqlPipe pipe = SqlContext.Pipe; SqlDataReader reader; if (triggerContext.TriggerAction == TriggerAction.Insert) { using (SqlConnection connection = new SqlConnection(@"context connection=true")) { connection.Open(); command = new SqlCommand(@"SELECT * FROM INSERTED", connection); reader = command.ExecuteReader(); reader.Read();
Note. GetTransaction is the name of the trigger you want to create, in this case Evnlog is the name of the table
demo.b
source share