SqlServiceBrokerListener 3.0.0

dotnet add package SqlServiceBrokerListener --version 3.0.0
                    
NuGet\Install-Package SqlServiceBrokerListener -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SqlServiceBrokerListener" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SqlServiceBrokerListener" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SqlServiceBrokerListener" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SqlServiceBrokerListener --version 3.0.0
                    
#r "nuget: SqlServiceBrokerListener, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SqlServiceBrokerListener@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SqlServiceBrokerListener&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SqlServiceBrokerListener&version=3.0.0
                    
Install as a Cake Tool

SqlServiceBrokerListener

A .NET library for listening to SQL Server Service Broker notifications and reporting table inserts, updates, and deletes to your application.

  • Targets .NET 10 and .NET 11.
  • Uses Microsoft.Data.SqlClient.
  • MIT licensed.

Install

Add the NuGet package to your project:

dotnet add package SqlServiceBrokerListener

Or use the Package Manager Console:

Install-Package SqlServiceBrokerListener

Requirements

  • SQL Server Service Broker must be enabled for the target database. For example:

    ALTER DATABASE [YourDatabase] SET ENABLE_BROKER;
    
  • The database user in your connection string needs permissions to install and use the listener's Service Broker objects. These include CREATE PROCEDURE, CREATE SERVICE, CREATE QUEUE, SUBSCRIBE QUERY NOTIFICATIONS, CONTROL on the listener schema, and REFERENCES on the DEFAULT contract. Grant only the permissions appropriate for your environment.

  • The listener's default schema is dbo.

Listen for table changes

using SqlServiceBrokerListener;

using var listener = new SqlDependencyEx(
    connectionString,
    "YourDatabase",
    "YourTable");

listener.TableChanged += (_, e) =>
{
    Console.WriteLine($"Change: {e.NotificationType}");
    Console.WriteLine(e.Data); // XML with inserted and/or deleted rows, when details are enabled
};

listener.Start();
// Keep the application running while notifications are needed.
// Dispose the listener (or call Stop()) when finished.

The constructor also accepts schemaName (default "dbo"), listenerType, receiveDetails, and identity. By default, the listener reports inserts, updates, and deletes and includes changed-row details. e.NotificationType is one of Insert, Update, Delete, or None.

To listen for updates only:

var listener = new SqlDependencyEx(
    connectionString,
    "YourDatabase",
    "YourTable",
    listenerType: SqlDependencyEx.NotificationTypes.Update);

Set receiveDetails: false when you only need notification types and do not need the changed-row XML. In that mode, e.Data is null and e.NotificationType is None.

Multiple listeners and application instances

Use a distinct identity for each listener that may be active at the same time. Choose identities that are unique across application instances that share the same database:

var first = new SqlDependencyEx(connectionString, "YourDatabase", "Orders", identity: 1);
var second = new SqlDependencyEx(connectionString, "YourDatabase", "Customers", identity: 2);

Command-line listener

The repository also includes a console listener. Run it with a connection string, database, and table:

dotnet run --project SqlServiceBrokerListener/SqlServiceBrokerListener.Tablelistener.Core -- \
  --connectionstring "Data Source=server;Initial Catalog=YourDatabase;Integrated Security=True;TrustServerCertificate=True" \
  --database YourDatabase \
  --table YourTable

Use --help to display the command-line options. The program waits for a key press; press x to stop listening.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 168 11/11/2026
2.0.0 28,683 7/11/2019