I have developed ucma C# console application which sends IM to users.
Now I want to send IM if any new entry is added in the table
So i want to use query notification .
I have enabled service broker on my database .
And I have added code for sqldepedency in my code file.
as follows.
public static void Main(string[] args) { UCMASampleInstantMessagingCall ucmaSampleInstantMessagingCall = new UCMASampleInstantMessagingCall(); ucmaSampleInstantMessagingCall.connectionfunction();
}
public void connectionfunction()string connectionString = @"Data Source=PIXEL-IHANNAH2\PPINSTANCE;User ID=sqlPPUser;Password=ppuser1;Initial Catalog=Ian;";
SqlDependency.Stop(connectionString);
SqlConnection sqlConnection = new SqlConnection(connectionString);string statement = "select * from dbo.tblTest";
SqlCommand sqlCommand = new SqlCommand(statement, sqlConnection);// Create and bind the SqlDependency object to the command object.
SqlDependency dependency = new SqlDependency(sqlCommand, null, 0);
SqlDependency.Start(connectionString);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
}
privatevoid dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
ucmaSampleInstantMessagingCall.run()
}
private void Run() { // Initialize and startup the platform. Exception ex = null; try { // Create the UserEndpoint _helper = new UCMASampleHelper(); _userendpoint = _helper.CreateEstablishedUserEndpoint();
Now I want to run this application in the background , so f any new entry is added it will notify my C# application and call run function.
i tried above code but it was not working.
Sample code is avaliableon net but it is for form application and we can see output if we run the form application .
so if i want to run my C# application what should I do?