title: How to trigger C# method using SQL Server Service Broker from stored procedure without using SqlDependency?
body: <p>I want to call a C# method when I insert a new record into a table and insert xml into service broker queue from the stored procedure. I am able to perform it by using <code>SqlDependency</code>, but I don't need this - I want to perform it using the stored procedure. </p>
  
  <p>You can see my code using the <code>SqlDependecy</code>. But I want another way to call C# method from a stored procedure using SQL Server Service Broker (not DB to DB). </p>
  
  <pre><code>public void Notification()
  {
      using (var connection = new SqlConnection(connectionString))
      {
          connection.Open();
  
          var queryString = "SELECT [ID] FROM [dbo].[Message]";
  
          using (var oCommand = new SqlCommand(queryString, connection))
          {
              // Starting the listener infrastructure...
              SqlDependency.Stop(connectionString, "queueName");
              SqlDependency.Start(connectionString, "queueName");
  
              var oDependency = new SqlDependency(oCommand);
              oDependency.OnChange += OnNotificationChange;
  
              // NOTE: You have to execute the command, or the notification will never fire.
              oCommand.ExecuteReader();
          }
      }
  }
  
  private void ChangeNotification(object sender, SqlNotificationEventArgs e)
  {
      Console.WriteLine("Notification Info: " + e.Info);
      //Re-register the SqlDependency. 
      //var oDependency = new SqlDependency();
      //oDependency.OnChange -= OnNotificationChange;
      RegisterForNotification();
  }
  </code></pre>