我写了一个clr触发器,每当一个新文件插入到我的表中,然后将值传递给我的WCF服务,现在我必须更改进程“更新”只有特定列得到更新,然后我必须从其他两个表中拉出值。CLR触发器只有特定列得到更新
我只是想知道的是,无论如何,我可以启动clr触发器只是特定的列更新?
这样
表1中的场景:客户详细信息(Cust.No,Cust.Name,DESC)
表2:地址(DoorNo,街道,城市,州)。
这里试图做什么,如果Table1中的“Desc”列被更新,那么clr触发器会被触发并根据“Desc”传递Table1和Table2中的所有值。
这里是我的插入代码:
[Microsoft.SqlServer.Server.SqlTrigger(Name = "WCFTrigger",Target = "tbCR", Event = "FOR UPDATE, INSERT")]
public static void Trigger1()
{
SqlCommand cmd;
SqlTriggerContext myContext = SqlContext.TriggerContext;
SqlPipe pipe = SqlContext.Pipe;
SqlDataReader reader;
if(myContext.TriggerAction== TriggerAction.Insert)
{
using (SqlConnection conn = new SqlConnection(@"context connection=true"))
{
conn.Open();
//cmd = new SqlCommand(@"SELECT * FROM tbCR", conn);
cmd = new SqlCommand(@"SELECT * FROM INSERTED", conn);
reader = cmd.ExecuteReader();
reader.Read();
//get the insert value's here
string Cust.No, Cust.Name,Desc;
Cust.No = reader[0].ToString();
Cust.Name = reader[1].ToString();
Desc = reader[2].ToString();
myclient.InsertOccured(Cust.No, Cust.Name,Desc);
reader.Dispose();
}
}
}
,非常感谢您的评论,所以最好的解决方法是什么?情况? – Usher 2012-02-23 01:35:56
你在通知什么? – 2012-02-23 01:40:47
我在我的本地机器上通过我的clr触发器调用wcf,并解决了任何问题,但是您的回答让我对生产环境感到恐慌,所以想从Windows服务或c#端的其他任何替代方法中寻找答案。建议我对这些不熟悉,但我有限的时间来完成改变触发过程。 – Usher 2012-02-23 01:52:46