├── .gitignore
├── LICENSE
├── README.md
└── SqlDependencyNotificationDemo
├── App.config
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── Query - Monitoring Data Change with SqlDependency using C#.sql
├── Settings.StyleCop
├── SqlDependencyNotificationSample.csproj
└── SqlDependencyNotificationSample.snk
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 | *.pubxml
98 |
99 | # NuGet Packages Directory
100 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
101 | #packages/
102 |
103 | # Windows Azure Build Output
104 | csx
105 | *.build.csdef
106 |
107 | # Windows Store app package directory
108 | AppPackages/
109 |
110 | # Others
111 | sql/
112 | *.Cache
113 | ClientBin/
114 | [Ss]tyle[Cc]op.*
115 | ~$*
116 | *~
117 | *.dbmdl
118 | *.[Pp]ublish.xml
119 | *.pfx
120 | *.publishsettings
121 |
122 | # RIA/Silverlight projects
123 | Generated_Code/
124 |
125 | # Backup & report files from converting an old project file to a newer
126 | # Visual Studio version. Backup files are not needed, because we have git ;-)
127 | _UpgradeReport_Files/
128 | Backup*/
129 | UpgradeLog*.XML
130 | UpgradeLog*.htm
131 |
132 | # SQL Server files
133 | App_Data/*.mdf
134 | App_Data/*.ldf
135 |
136 | # =========================
137 | # Windows detritus
138 | # =========================
139 |
140 | # Windows image file caches
141 | Thumbs.db
142 | ehthumbs.db
143 |
144 | # Folder config file
145 | Desktop.ini
146 |
147 | # Recycle Bin used on file shares
148 | $RECYCLE.BIN/
149 |
150 | # Mac crap
151 | .DS_Store
152 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jsinh.in Blog
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SqlDependencySample01
2 | =====================
3 |
4 | SQL dependency sample 01
5 |
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/Program.cs:
--------------------------------------------------------------------------------
1 | #region Copyright Quipment
2 | //-----------------------------------------------------------------------------------------------------------------------------------------------------
3 | //
4 | // Copyright (c) 2013 Jsinh.in. All rights reserved.
5 | //
6 | //
7 | // Sample program to demonstrate SqlDependency for SQL Server using C#.
8 | //
9 | //-----------------------------------------------------------------------------------------------------------------------------------------------------
10 | #endregion
11 |
12 | namespace SqlDependencyNotificationSample
13 | {
14 | #region Namespace
15 |
16 | using System;
17 | using System.Configuration;
18 | using System.Data;
19 | using System.Data.SqlClient;
20 |
21 | #endregion
22 |
23 | ///
24 | /// Sample program.
25 | ///
26 | public class Program : IDisposable
27 | {
28 | #region Variable declaration
29 |
30 | ///
31 | /// Option selected.
32 | ///
33 | private static string optionSelected;
34 |
35 | ///
36 | /// Sample connection string.
37 | ///
38 | private readonly string sampleConnectionString;
39 |
40 | ///
41 | /// Notification query.
42 | ///
43 | private readonly string notificationQuery;
44 |
45 | ///
46 | /// Notification stored procedure.
47 | ///
48 | private readonly string notificationStoredProcedure;
49 |
50 | ///
51 | /// Instance of SQL dependency.
52 | ///
53 | private SqlDependency sampleSqlDependency;
54 |
55 | ///
56 | /// SQL command.
57 | ///
58 | private SqlCommand sampleSqlCommand;
59 |
60 | ///
61 | /// SQL connection
62 | ///
63 | private SqlConnection sampleSqlConnection;
64 |
65 | #endregion
66 |
67 | #region Constructor
68 |
69 | ///
70 | /// Prevents a default instance of the class from being created.
71 | ///
72 | private Program()
73 | {
74 | this.sampleConnectionString = ConfigurationManager.ConnectionStrings["SampleDbConnection"].ConnectionString;
75 | this.notificationQuery = "SELECT [SampleId],[SampleName],[SampleCategory],[SampleDateTime],[IsSampleProcessed] FROM [dbo].[SampleTable01];";
76 | this.notificationStoredProcedure = "uspGetSampleInformation";
77 | }
78 |
79 | #endregion
80 |
81 | #region Methods
82 |
83 | ///
84 | /// Main method.
85 | ///
86 | /// Input arguments.
87 | public static void Main(string[] args)
88 | {
89 | var program = new Program();
90 | Console.WriteLine("Select from the below options:");
91 | Console.WriteLine("1. SqlDependency using Stored procedure and default Queue");
92 | Console.WriteLine("2. SqlDependency using Stored procedure and specific Queue");
93 | Console.WriteLine("3. SqlDependency using text query and default Queue");
94 | Console.WriteLine("4. SqlDependency using text query and specific Queue");
95 | optionSelected = Console.ReadLine();
96 | switch (optionSelected)
97 | {
98 | case "1":
99 | case "3":
100 | program.RegisterDependencyUsingDefaultQueue();
101 | break;
102 | case "2":
103 | case "4":
104 | program.RegisterDependencyUsingSpecificQueue();
105 | break;
106 | }
107 |
108 | Console.ReadLine();
109 | program.Dispose();
110 | }
111 |
112 | ///
113 | /// Dispose all used resources.
114 | ///
115 | public void Dispose()
116 | {
117 | if (null != this.sampleSqlDependency)
118 | {
119 | this.sampleSqlDependency.OnChange -= null;
120 | }
121 |
122 | if (null != this.sampleSqlCommand)
123 | {
124 | this.sampleSqlCommand.Dispose();
125 | }
126 |
127 | if (null != this.sampleSqlConnection)
128 | {
129 | this.sampleSqlConnection.Dispose();
130 | }
131 |
132 | this.sampleSqlDependency = null;
133 | this.sampleSqlCommand = null;
134 | this.sampleSqlConnection = null;
135 |
136 | if (optionSelected.Equals("1") || optionSelected.Equals("3"))
137 | {
138 | SqlDependency.Stop(this.sampleConnectionString);
139 | }
140 | else if (optionSelected.Equals("2") || optionSelected.Equals("4"))
141 | {
142 | SqlDependency.Start(this.sampleConnectionString, "QueueSampleInformationDataChange");
143 | }
144 | }
145 |
146 | ///
147 | /// Register dependency using default queue name.
148 | ///
149 | private void RegisterDependencyUsingDefaultQueue()
150 | {
151 | SqlDependency.Stop(this.sampleConnectionString);
152 | SqlDependency.Stop(this.sampleConnectionString, "QueueSampleInformationDataChange");
153 | SqlDependency.Start(this.sampleConnectionString);
154 | if (optionSelected.Equals("1"))
155 | {
156 | this.ConfigureDependencyUsingStoreProcedureAndDefaultQueue();
157 | }
158 | else if (optionSelected.Equals("3"))
159 | {
160 | this.ConfigureDependencyUsingTextQueryAndDefaultQueue();
161 | }
162 | }
163 |
164 | ///
165 | /// Register dependency using specific queue name.
166 | ///
167 | private void RegisterDependencyUsingSpecificQueue()
168 | {
169 | SqlDependency.Stop(this.sampleConnectionString);
170 | SqlDependency.Stop(this.sampleConnectionString, "QueueSampleInformationDataChange");
171 | SqlDependency.Start(this.sampleConnectionString, "QueueSampleInformationDataChange");
172 | if (optionSelected.Equals("2"))
173 | {
174 | this.ConfigureDependencyUsingStoreProcedureAndSpecificQueue();
175 | }
176 | else if (optionSelected.Equals("4"))
177 | {
178 | this.ConfigureDependencyUsingTextQueryAndSpecificQueue();
179 | }
180 | }
181 |
182 | ///
183 | /// Configure dependency using stored procedure and specified queue.
184 | ///
185 | private async void ConfigureDependencyUsingStoreProcedureAndDefaultQueue()
186 | {
187 | if (null != this.sampleSqlDependency)
188 | {
189 | this.sampleSqlDependency.OnChange -= null;
190 | }
191 |
192 | if (null != this.sampleSqlCommand)
193 | {
194 | this.sampleSqlCommand.Dispose();
195 | }
196 |
197 | if (null != this.sampleSqlConnection)
198 | {
199 | this.sampleSqlConnection.Dispose();
200 | }
201 |
202 | this.sampleSqlDependency = null;
203 | this.sampleSqlCommand = null;
204 | this.sampleSqlConnection = null;
205 |
206 | //// Create connection.
207 | this.sampleSqlConnection = new SqlConnection(this.sampleConnectionString);
208 |
209 | //// Create command.
210 | this.sampleSqlCommand = new SqlCommand { Connection = this.sampleSqlConnection };
211 | this.sampleSqlCommand.CommandType = CommandType.StoredProcedure;
212 | this.sampleSqlCommand.CommandText = this.notificationStoredProcedure;
213 | this.sampleSqlCommand.Notification = null;
214 |
215 | //// Create Sql Dependency.
216 | this.sampleSqlDependency = new SqlDependency(this.sampleSqlCommand);
217 | this.sampleSqlDependency.OnChange += this.SqlDependencyOnChange;
218 | await this.sampleSqlCommand.Connection.OpenAsync();
219 | await this.sampleSqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection);
220 |
221 | if (null != this.sampleSqlCommand)
222 | {
223 | this.sampleSqlCommand.Dispose();
224 | }
225 |
226 | if (null != this.sampleSqlConnection)
227 | {
228 | this.sampleSqlConnection.Dispose();
229 | }
230 | }
231 |
232 | ///
233 | /// Configure dependency using stored procedure and specified queue.
234 | ///
235 | private async void ConfigureDependencyUsingTextQueryAndDefaultQueue()
236 | {
237 | if (null != this.sampleSqlDependency)
238 | {
239 | this.sampleSqlDependency.OnChange -= null;
240 | }
241 |
242 | if (null != this.sampleSqlCommand)
243 | {
244 | this.sampleSqlCommand.Dispose();
245 | }
246 |
247 | if (null != this.sampleSqlConnection)
248 | {
249 | this.sampleSqlConnection.Dispose();
250 | }
251 |
252 | this.sampleSqlDependency = null;
253 | this.sampleSqlCommand = null;
254 | this.sampleSqlConnection = null;
255 |
256 | //// Create connection.
257 | this.sampleSqlConnection = new SqlConnection(this.sampleConnectionString);
258 |
259 | //// Create command.
260 | this.sampleSqlCommand = new SqlCommand { Connection = this.sampleSqlConnection };
261 | this.sampleSqlCommand.CommandType = CommandType.Text;
262 | this.sampleSqlCommand.CommandText = this.notificationQuery;
263 | this.sampleSqlCommand.Notification = null;
264 |
265 | //// Create Sql Dependency.
266 | this.sampleSqlDependency = new SqlDependency(this.sampleSqlCommand);
267 | this.sampleSqlDependency.OnChange += this.SqlDependencyOnChange;
268 | await this.sampleSqlCommand.Connection.OpenAsync();
269 | await this.sampleSqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection);
270 |
271 | if (null != this.sampleSqlCommand)
272 | {
273 | this.sampleSqlCommand.Dispose();
274 | }
275 |
276 | if (null != this.sampleSqlConnection)
277 | {
278 | this.sampleSqlConnection.Dispose();
279 | }
280 | }
281 |
282 | ///
283 | /// Configure dependency using stored procedure and specified queue.
284 | ///
285 | private async void ConfigureDependencyUsingStoreProcedureAndSpecificQueue()
286 | {
287 | if (null != this.sampleSqlDependency)
288 | {
289 | this.sampleSqlDependency.OnChange -= null;
290 | }
291 |
292 | if (null != this.sampleSqlCommand)
293 | {
294 | this.sampleSqlCommand.Dispose();
295 | }
296 |
297 | if (null != this.sampleSqlConnection)
298 | {
299 | this.sampleSqlConnection.Dispose();
300 | }
301 |
302 | this.sampleSqlDependency = null;
303 | this.sampleSqlCommand = null;
304 | this.sampleSqlConnection = null;
305 |
306 | //// Create connection.
307 | this.sampleSqlConnection = new SqlConnection(this.sampleConnectionString);
308 |
309 | //// Create command.
310 | this.sampleSqlCommand = new SqlCommand { Connection = this.sampleSqlConnection };
311 | this.sampleSqlCommand.CommandType = CommandType.StoredProcedure;
312 | this.sampleSqlCommand.CommandText = this.notificationStoredProcedure;
313 | this.sampleSqlCommand.Notification = null;
314 |
315 | //// Create Sql Dependency.
316 | this.sampleSqlDependency = new SqlDependency(this.sampleSqlCommand, "service=ServiceSampleInformationDataChange;Local database=SampleDb", 432000);
317 | this.sampleSqlDependency.OnChange += this.SqlDependencyOnChange;
318 | await this.sampleSqlCommand.Connection.OpenAsync();
319 | await this.sampleSqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection);
320 |
321 | if (null != this.sampleSqlCommand)
322 | {
323 | this.sampleSqlCommand.Dispose();
324 | }
325 |
326 | if (null != this.sampleSqlConnection)
327 | {
328 | this.sampleSqlConnection.Dispose();
329 | }
330 | }
331 |
332 | ///
333 | /// Configure dependency using stored procedure and specified queue.
334 | ///
335 | private async void ConfigureDependencyUsingTextQueryAndSpecificQueue()
336 | {
337 | if (null != this.sampleSqlDependency)
338 | {
339 | this.sampleSqlDependency.OnChange -= null;
340 | }
341 |
342 | if (null != this.sampleSqlCommand)
343 | {
344 | this.sampleSqlCommand.Dispose();
345 | }
346 |
347 | if (null != this.sampleSqlConnection)
348 | {
349 | this.sampleSqlConnection.Dispose();
350 | }
351 |
352 | this.sampleSqlDependency = null;
353 | this.sampleSqlCommand = null;
354 | this.sampleSqlConnection = null;
355 |
356 | //// Create connection.
357 | this.sampleSqlConnection = new SqlConnection(this.sampleConnectionString);
358 |
359 | //// Create command.
360 | this.sampleSqlCommand = new SqlCommand { Connection = this.sampleSqlConnection };
361 | this.sampleSqlCommand.CommandType = CommandType.Text;
362 | this.sampleSqlCommand.CommandText = this.notificationQuery;
363 | this.sampleSqlCommand.Notification = null;
364 |
365 | //// Create Sql Dependency.
366 | this.sampleSqlDependency = new SqlDependency(this.sampleSqlCommand, "service=ServiceSampleInformationDataChange;Local database=SampleDb", 432000);
367 | this.sampleSqlDependency.OnChange += this.SqlDependencyOnChange;
368 | await this.sampleSqlCommand.Connection.OpenAsync();
369 | await this.sampleSqlCommand.ExecuteReaderAsync(CommandBehavior.CloseConnection);
370 |
371 | if (null != this.sampleSqlCommand)
372 | {
373 | this.sampleSqlCommand.Dispose();
374 | }
375 |
376 | if (null != this.sampleSqlConnection)
377 | {
378 | this.sampleSqlConnection.Dispose();
379 | }
380 | }
381 |
382 | ///
383 | /// Event handler for SQL dependency notification on change event.
384 | ///
385 | /// Sender object.
386 | /// Event arguments.
387 | private void SqlDependencyOnChange(object sender, SqlNotificationEventArgs eventArgs)
388 | {
389 | if (eventArgs.Info == SqlNotificationInfo.Invalid)
390 | {
391 | Console.WriteLine("The above notification query is not valid.");
392 | }
393 | else
394 | {
395 | Console.WriteLine("Notification Info: " + eventArgs.Info);
396 | Console.WriteLine("Notification source: " + eventArgs.Source);
397 | Console.WriteLine("Notification type: " + eventArgs.Type);
398 | }
399 |
400 | switch (optionSelected)
401 | {
402 | case "1":
403 | this.ConfigureDependencyUsingStoreProcedureAndDefaultQueue();
404 | break;
405 | case "2":
406 | this.ConfigureDependencyUsingStoreProcedureAndSpecificQueue();
407 | break;
408 | case "3":
409 | this.ConfigureDependencyUsingTextQueryAndDefaultQueue();
410 | break;
411 | case "4":
412 | this.ConfigureDependencyUsingTextQueryAndSpecificQueue();
413 | break;
414 | }
415 | }
416 |
417 | #endregion
418 | }
419 | }
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SqlDependencyNotificationSample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SqlDependencyNotificationSample")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("25b68946-ce7b-4716-a689-80c5c2b4aaf7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/Query - Monitoring Data Change with SqlDependency using C#.sql:
--------------------------------------------------------------------------------
1 | --***************************************************
2 | --Monitoring Data Change with SqlDependency using C#
3 | --***************************************************
4 |
5 | --## Check Service Broker Enabled / Disbled for database.
6 | --USE [SampleDb]
7 | --GO
8 | --SELECT NAME, IS_BROKER_ENABLED FROM SYS.DATABASES
9 |
10 |
11 | --## Enable / Disable Service Broker for existing database.
12 | --USE [SampleDb]
13 | --GO
14 | --ALTER DATABASE SampleDb SET ENABLE_BROKER
15 | --ALTER DATABASE SampleDb SET DISABLE_BROKER
16 |
17 | --## Create sample table in SampleDb database
18 | --USE [SampleDb]
19 | --GO
20 | --CREATE TABLE [dbo].[SampleTable02](
21 | -- [SampleId] [bigint] IDENTITY(1,1) NOT NULL,
22 | -- [SampleName] [nvarchar](50) NOT NULL,
23 | -- [SampleCategory] [nvarchar](50) NOT NULL,
24 | -- [SampleDateTime] [datetime] NOT NULL,
25 | -- [IsSampleProcessed] [bit] NOT NULL)
26 | -- ON [PRIMARY];
27 |
28 | --## Create stored procedure for query notification
29 | --USE [SampleDb]
30 | --GO
31 | --CREATE PROCEDURE uspGetSampleInformation
32 | --AS
33 | --BEGIN
34 | -- SELECT
35 | -- [SampleId],
36 | -- [SampleName],
37 | -- [SampleCategory],
38 | -- [SampleDateTime],
39 | -- [IsSampleProcessed]
40 | -- FROM
41 | -- [dbo].[SampleTable01];
42 | --END
43 |
44 | --## Create QUEUE and SERVICE for the query
45 | --USE [SampleDb]
46 | --GO
47 | --CREATE QUEUE QueueSampleInformationDataChange
48 | --CREATE SERVICE ServiceSampleInformationDataChange
49 | -- ON QUEUE QueueSampleInformationDataChange
50 | -- ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);
51 |
52 | --GRANT SUBSCRIBE QUERY NOTIFICATIONS TO YourSqlUserName;
53 |
54 | --## Give authorization for the Sql user to SampleDb database
55 | --ALTER AUTHORIZATION ON DATABASE::SampleDb TO YourSqlUserName;
56 |
57 | --## Grand send permission on Service broker service you created for user that will be used to run the client application
58 | --GRANT SEND ON SERVICE:: ServiceSampleInformationDataChange TO [YourMachineNameOrDomain\UserName];
59 |
60 | --## Grand send permission on Service broker queue you created for user that will be used to run the client application
61 | --GRANT RECEIVE ON dbo.QueueSampleInformationDataChange TO [YourMachineNameOrDomain\UserName];
62 |
63 | --## Use this query to see the current queue subscriptions
64 | --SELECT * FROM SYS.DM_QN_SUBSCRIPTIONS
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/Settings.StyleCop:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Qonfig
5 |
6 |
7 |
8 |
9 |
10 | False
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/SqlDependencyNotificationSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F4962BE8-E3B1-4E90-9DF0-A859AC8C7724}
8 | Exe
9 | Properties
10 | SqlDependencyNotificationSample
11 | SqlDependencyNotificationSample
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | bin\Debug\SqlDependencyNotificationSample.XML
25 | MinimumRecommendedRules.ruleset
26 | true
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | true
39 |
40 |
41 | SqlDependencyNotificationSample.snk
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
73 |
--------------------------------------------------------------------------------
/SqlDependencyNotificationDemo/SqlDependencyNotificationSample.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsinh-blog-code/SqlDependencySample01/0267b67b1ebb8be71adfb07cfe0592ecc5132718/SqlDependencyNotificationDemo/SqlDependencyNotificationSample.snk
--------------------------------------------------------------------------------