You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### [Buy me a Coffee ☕](https://www.buymeacoffee.com/cajuncoding)
8
13
*I'm happy to share with the community, but if you find this useful (e.g for professional use), and are so inclinded,
9
14
then I do love-me-some-coffee!*
@@ -12,23 +17,24 @@ then I do love-me-some-coffee!*
12
17
<imgsrc="https://cdn.buymeacoffee.com/buttons/default-orange.png"alt="Buy Me A Coffee"height="41"width="174">
13
18
</a>
14
19
15
-
#### SqlClient Namespaces:
16
-
There are two namespaces for SqlClient, and this library supports both:
20
+
## Sql Server Details:
21
+
#### Both SqlClient Namespaces are Supported:
22
+
The library supports both SqlClient libraries:
17
23
- System.Data.SqlClient (Legacy; long term supported for existing applications)
18
24
- Microsoft.Data.SqlClient (Future; recommended go-forward library for new applications)
19
25
20
26
The usage for both is identical, with only the import being different based on the library you are using (or both in some edge cases):
21
27
-`using SqlAppLockHelper.SystemDataNS;`
22
28
-`using SqlAppLockHelper.MicrosoftDataNS;`
23
29
24
-
#### Locking Scopes (maps to the `@LockOwner` parameter of `sp_getapplock`):
30
+
#### Both Transaction & Connection Locking Scopes are supported:
25
31
There are two scopes for Locks that are supported:
26
-
- Session Scope (will automatically be released by Sql Server when the Sql Connection is disposed/closed; or may be optionally explicitly released).
27
-
- Transaction Scope (Will automatically be released by Sql Server when Sql Transaction is Commited/Rolled-back/Closed; or can be optionally explicitly released).
28
-
29
-
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.
32
+
-**Session Scope** (aka Connection) - will automatically be released by Sql Server when the Sql Connection is disposed/closed; or may be optionally explicitly released.
33
+
-**Transaction Scope** - Will automatically be released by Sql Server when Sql Transaction is Commited/Rolled-back/Closed; or can be optionally explicitly released.
34
+
35
+
_NOTE: These scopes map to the underlying maps to the `@LockOwner` parameter of `sp_getapplock`_)
30
36
31
-
####Usage Notes:
37
+
### Usage Notes:
32
38
- The generally recommended approach is to use the *Transaction* scope because it is slightly safer (e.g. more resilient against
33
39
abandoned locks) by allowing the Locks to automatically expire with the Transaction; and is the default behavior of Sql Server.
34
40
- 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.
### Releasing Locks with IDisposable/IAsyncDisposable Patterns:
50
+
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.
51
+
52
+
### Use Cases:
44
53
- Provide a lock implementation similar to C# `lock (...) {}` but on a distributed scale across many instances of an
0 commit comments