Ask a questionAsk a question
 

QuestionSqlDependency only some colum?

  • Friday, October 30, 2009 4:01 AMKevein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "select id from dbo.table"; // Only one column!
    cmd.CommandType = CommandType.Text; 
    SqlDependency d = new SqlDependency( cmd );
    d.OnChange += new OnChangeEventHandler(dependency_OnChange);
    I change the value of any field in table , dependency_OnChange is Excute.
    I just want when id changed,dependency_OnChange is Excute

    • Moved byBob BeaucheminMVP, AnswererFriday, October 30, 2009 4:38 AMMoved to a more appropriate group (From:.NET Framework inside SQL Server)
    •  

All Replies

  • Friday, October 30, 2009 4:37 AMBob BeaucheminMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That is the only way that SqlDependency works. There is no way to change this behavior. Any field change will fire the dependency and the dependency message does not specify which column or rows have changed.

    Bob Beauchemin
    SQLskills
  • Wednesday, November 04, 2009 4:32 AMNai-dong Jin - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Just as Bob said, any filed change will fire the denpendency. In you case, I think you need to use trigger instead, when the table got updated, you need to check the origial value and the update value mannually, and try to fire some relevant event you defined.

    Thanks.
    Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.