Sqldependency c# là gì

PreviousNext

C# SqlDependency Start(string connectionString) Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string.

From Type:

System.Data.SqlClient.SqlDependency

Start() is a method.

Syntax

Start is defined as:

public static bool Start (string connectionString);

Parameters:

C# SqlDependency Start() has the following parameters:

  • connectionString - The connection string for the instance of SQL Server from which to obtain change notifications.

Return

true if the listener initialized successfully; false if a compatible listener already exists.

Example

The following examples show how to use C# SqlDependency.Start(string connectionString).

Example 1

using System.Configuration; using System.Data.SqlClient; using System.Web.Mvc; using System.Web.Routing; using Owin;/* w ww . d e m o 2 s . c o m*/ namespace SignelRDB { public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteTable.Routes.MapOwinRoute("Home/Index", app => app.RunSignalR()); RouteConfig.RegisterRoutes(RouteTable.Routes); SqlDependency.Start(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); } protected void Application_End() { SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); } } }

Example 2

using System;/* w w w . d e m o 2 s. c o m */ using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; namespace SMS { public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); SqlDependency.Start(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); } protected void Application_End() { SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); } } }

Example 3

using System;// w w w .d e m o 2 s . c o m using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using System.Configuration; namespace SignalRScaleOutNotifications { public class MvcApplication : System.Web.HttpApplication { string connString = ConfigurationManager.ConnectionStrings["signalRConnection"].ConnectionString; protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); SqlDependency.Start(connString); } protected void Application_End() { SqlDependency.Stop(connString); } } }

PreviousNext

Related

  • C# SqlDependency SqlDependency(System.Data.SqlClient.SqlCommand command, string options, int timeout)
  • C# SqlDependency Id
  • C# SqlDependency OnChange
  • C# SqlDependency Start(string connectionString)
  • C# SqlDependency Start(string connectionString, string queue)
  • C# SqlDependency Stop(string connectionString)
  • C# SqlDependency Stop(string connectionString, string queue)

Chủ đề