Skip to content

Commit 14ed4df

Browse files
authored
General edites for clarity
Removed residual risks comments as testing proves that proper disposal/closing of connections releases the locks correctly.
1 parent 84f66f0 commit 14ed4df

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ The usage for both is identical, with only the import being different based on t
1515

1616
#### Locking Scopes (maps to the `@LockOwner` parameter of `sp_getapplock`):
1717
There are two scopes for Locks that are supported:
18-
- Session Scope (requires expclit release; implemented as IDisposable/IAsyncDisposable to provide reliable release via C# `using` pattern)
19-
- Transaction Scope (can be optionally released, but will automatically be released by SqlServer when Transaction is Commited/Rolled-back/Closed).
18+
- Session Scope (will automatically be released by Sql Server when the Sql Connection is disposed/closed; or may be optionally explicitly released).
19+
- Transaction Scope (Will automatically be released by Sql Server when Sql Transaction is Commited/Rolled-back/Closed; or can be optionally explicitly released).
20+
21+
Note: Explicit release can be done anytime from the `SqlServerAppLock` class returned from an acquired lock, and is also intrinsically done via IDisposable/IAsyncDisposable on the `SqlServerAppLock` class to provide reliable release when scope closes via C# `using` pattern.
2022

2123
#### Usage Notes:
22-
- The generally recommended approach is to use the *Transaction* scope because it is slightly safer (e.g. more resilient agains
24+
- The generally recommended approach is to use the *Transaction* scope because it is slightly safer (e.g. more resilient against
2325
abandoned locks) by allowing the Locks to automatically expire with the Transaction; and is the default behavior of Sql Server.
24-
- However the *Session* scope is reliably implemented via IDisposable/IAsyncDisposable C# interfaces leaving
25-
the main residual risk of Database communication or Network issues, whereby if we can't communicate with the DB then we can't explicity release the lock.
26+
- However the *Session* scope is reliably implemented as long as you always close/dispose of the connection and/or via the `SqlServerAppLock` class; which also implements IDisposable/IAsyncDisposable C# interfaces.
2627
- The lock _acquisition timeout_ value is the value (in seconds) for which Sql Server will try and wait for Lock Acquisition. By specifying Zero
2728
(0 seconds) then Sql Server will attempt to get the lock but immediately fail lock acquisition and return if it cannot
2829
acquire the lock.
@@ -33,10 +34,10 @@ acquire the lock.
3334

3435
#### Use Cases:
3536
- Provide a lock implementation similar to C# `lock (...) {}` but on a distributed scale across many instances of an
36-
application (e.g. Azure Functions, Load Balanced Servers, etc.) .
37-
- Provide a lock to ensure code is only ever run by one instance at a time (e.g. Bulk Loading or Bulk Synchronization processing,
37+
application (e.g. Azure Functions, Load Balanced Servers, etc.).
38+
- Provide a mutex lock to ensure code is only ever run by one instance at a time (e.g. Bulk Loading or Bulk Synchronization processing,
3839
Queue Processing logic, Transactional Outbox Pattern, etc.).
39-
- Many more I'm sure... but these are the ones that I've implemented in enterprises.
40+
- I'm sure there are many more... but these are the best examples that I've needed to implement in enterprises.
4041

4142

4243
## Nuget Package

0 commit comments

Comments
 (0)