Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SqlDependency supported in .NET Core?

Is it possible to leverage System.Data.SqlClient.SqlDependency from within a .NET Core v1.1 application? It appears that most of the other classes and methods within System.Data.SqlClient are available except SqlDependency.

Essentially, I'm trying to subscribe to SQL notifications when table data changes to then update the client's UI, so I'm open to other ways to achieve this if SqlDependency is not available from .NET Core.

Thanks in advance! Here's my complete project.json file:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "System.IdentityModel.Tokens.Jwt": "5.0.0",
    "Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Google": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "Microsoft.Extensions.Configuration.Binder": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Identity": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Rewrite": "1.0.0",
    "Microsoft.AspNetCore.ResponseCompression": "1.0.0",
    "Microsoft.AspNetCore.SignalR.Server": "0.2.0-*",
    "Microsoft.AspNetCore.WebSockets": "0.2.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netstandard1.1": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8",
        "net461",
        "dnxcore50"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "Views",
      "wwwroot",
      "appsettings.json",
      "appsettings.dev.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
like image 927
ianpoley Avatar asked Jan 15 '17 02:01

ianpoley


People also ask

What is SqlDependency C#?

SqlDependency allows you to receive notifications when the original data in the database changes so that the cache can be refreshed. To set up a dependency, you need to associate a SqlDependency object to one or more SqlCommand objects. To receive notifications, you need to subscribe to the OnChange event.

Is Ado net supported in .NET Core?

NET Core. So as long as you have a valid connection string to connect to your existing legacy database, you should be just fine.

Can .NET Framework run on .NET Core?

In order to run ASP.NET Core Apps on the . NET Framework it needs to only reference . Core NuGet packages which contains only the . NET Standard 2.0 builds.


2 Answers

According to this https://github.com/dotnet/corefx/issues/8188 it will be there in .NET Core 2.1, but I haven't seen anything about whether the usage differs from .NET Framework. I hope it doesn't.

like image 82
Aaron Hardin Avatar answered Nov 06 '22 03:11

Aaron Hardin


There's a .Net Core based open source solution available on GitHub : https://github.com/dyatchenko/ServiceBrokerListener

I'm not sure about the performance however, because it seems that the multiple client-app listening for changes are creating dedicated queues. So maybe it doesn't scale as good as the original SqlDependency.

like image 43
Micaël Félix Avatar answered Nov 06 '22 05:11

Micaël Félix