This thread is the continuation of the below thread Trigger Windows Service when the new record insert in to DB
I got the code from Demo.B suggested
public partial class Triggers
{
// Enter existing table or view for the target and uncomment the attribute line
[Microsoft.SqlServer.Server.SqlTrigger(Name = "Trigger_Web", Target = "StoryItems", Event = "FOR INSERT")]
public static void Trigger_Web()
{
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 StoryItems", connection);
reader = command.ExecuteReader();
reader.Read();
// get inserted value
string Name;
string Location;
Name = (string)reader[1];
Location =(string)reader[2];
reader.Close();
//try
//{
// // try to pass parameter to windows service
// //WindowsService param = new WindowService(Name, Location);
// //Do something if it pass
//}
//catch (Exception ex)
//{
//}
// Replace with your own code
SqlContext.Pipe.Send("Trigger FIRED");
}
}
}
}
I am facing few problem when i start execute,first of all it ask me change the version from 4.0 to lower (so changed the version to 3.5 in the properties).
When i try to step into its not working and all the time it says deploy succeed and the output window shows "Canceled by User". Am not sure what going on the behind scene.
Please some one advise me how can i execute and see some results when the new row is inserted.