Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ See [Breaking changes in ASP.NET Core 10](/aspnet/core/breaking-changes/10/overv
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change |
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change |
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change |
| [Named mutexes default to user scope on Unix](core-libraries/11/named-mutexes-unix-default-scope.md) | Behavioral change |
| [.NET runtime no longer provides default termination signal handlers](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change |
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible |
| [Type.MakeGenericSignatureType argument validation](reflection/10/makegeneric-signaturetype-validation.md) | Behavioral change |
Expand Down
1 change: 1 addition & 0 deletions docs/core/compatibility/11.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ See [Breaking changes in ASP.NET Core 11](/aspnet/core/breaking-changes/11/overv
| [Environment.GetCommandLineArgs()[0] preserves the apphost invocation name](core-libraries/11/environment-getcommandlineargs-apphost-invocation-name.md) | Behavioral change |
| [Environment.TickCount made consistent with Windows timeout behavior](core-libraries/11/environment-tickcount-windows-behavior.md) | Behavioral change |
| [Math.Round and MathF.Round return correctly rounded results](core-libraries/11/math-round-digits.md) | Behavioral change |
| [Named mutexes default to user scope on Unix](core-libraries/11/named-mutexes-unix-default-scope.md) | Behavioral change |
| [NamedPipeServerStream with PipeOptions.CurrentUserOnly tightens Unix socket file permissions](core-libraries/11/namedpipeserverstream-unix-permissions.md) | Behavioral change |
| [Nullable.GetUnderlyingType throws for custom Type subclasses](core-libraries/11/nullable-getunderlyingtype-throws.md) | Behavioral change |
| [PackagePart.GetStream() returns a non-seekable stream for compressed parts in ReadWrite packages](core-libraries/11/packagepart-getstream-non-seekable.md) | Behavioral change |
Expand Down
1 change: 1 addition & 0 deletions docs/core/compatibility/8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ See [Breaking changes in ASP.NET Core 8](/aspnet/core/breaking-changes/8/overvie
| [LDAP APIs not available on .NET Standard / .NET Framework](core-libraries/8.0/ldap-netstandard-apis.md) | Binary incompatible |
| [Legacy Console.ReadKey removed](core-libraries/8.0/console-readkey-legacy.md) | Behavioral change |
| [Method builders generate parameters with HasDefaultValue set to false](core-libraries/8.0/parameterinfo-hasdefaultvalue.md) | Behavioral change |
| [Named mutexes default to user scope on Unix](core-libraries/11/named-mutexes-unix-default-scope.md) | Behavioral change |
| [Package part URIs are now compared case-insensitively in System.IO.Packaging](core-libraries/8.0/system-io-packaging-case-insensitive-uri.md) | Behavioral change |
| [ProcessStartInfo.WindowStyle honored when UseShellExecute is false](core-libraries/8.0/processstartinfo-windowstyle.md) | Behavioral change |
| [RuntimeIdentifier returns platform for which runtime was built](core-libraries/8.0/runtimeidentifier.md) | Behavioral change |
Expand Down
1 change: 1 addition & 0 deletions docs/core/compatibility/9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ See [Breaking changes in ASP.NET Core 9](/aspnet/core/breaking-changes/9/overvie
| [IncrementingPollingCounter initial callback is asynchronous](core-libraries/9.0/async-callback.md) | Behavioral change | RC 1 |
| [Inline array struct size limit is enforced](core-libraries/9.0/inlinearray-size.md) | Behavioral change | Preview 1 |
| [InMemoryDirectoryInfo prepends rootDir to files](core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md) | Behavioral change | Preview 1 |
| [Named mutexes default to user scope on Unix](core-libraries/11/named-mutexes-unix-default-scope.md) | Behavioral change | 9.0.21 |
| [New TimeSpan.From*() overloads that take integers](core-libraries/9.0/timespan-from-overloads.md) | Source incompatible | Preview 3 |
| [New version of some OOB packages](core-libraries/9.0/oob-packages.md) | Source incompatible | Preview 5 |
| [RuntimeHelpers.GetSubArray returns different type](core-libraries/9.0/getsubarray-return.md) | Behavioral change | Preview 1 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "Breaking change: Named mutexes default to user scope on Unix"
description: "Learn about the breaking change in .NET 8, .NET 9, .NET 10, and .NET 11 where named mutexes on Unix default to user scope."
ms.date: 10/14/2026
ai-usage: ai-assisted
---

# Named mutexes default to user scope on Unix

Named mutexes on Unix now default to user scope instead of global scope. This change affects .NET 8.0.32, .NET 9.0.21, .NET 10.0.13, and .NET 11 RC 2.

## Version introduced

.NET 11 RC 2, .NET 10.0.13, .NET 9.0.21, and .NET 8.0.32

## Previous behavior

Previously, named mutexes on Unix were globally scoped by default, so processes run by different users could share them. User-scoped mutexes were available through <xref:System.Threading.Mutex> constructors that accept <xref:System.Threading.NamedWaitHandleOptions>, starting in .NET 10. Those mutexes were stored in a subdirectory of `/tmp/`.

## New behavior

Named mutexes on Unix now default to user scope. The runtime stores user-scoped mutex backing files in `$TMPDIR` on platforms where it's a per-user directory, such as macOS. Otherwise, it uses `$XDG_RUNTIME_DIR` if set. If neither directory is available, it uses a directory under the current user's home directory as defined in the user database, such as `/etc/passwd`; it doesn't use `$HOME`.

## Type of breaking change

This change is a [behavioral change](../../categories.md#behavioral-change).

## Reason for change

To improve security, named mutexes now default to a scope and storage location that restrict access to the current user. The previous `/tmp/` backing files could allow another user on the system to interfere with a named mutex. For more information, see [dotnet/docs issue #56396](https://github.com/dotnet/docs/issues/56396).

## Recommended action

If your named mutexes do not need cross-user access and your application can access the user-only directory for its platform, no change is required.

If your named mutexes need cross-user access, use a <xref:System.Threading.Mutex> constructor that accepts <xref:System.Threading.NamedWaitHandleOptions> on .NET 10 or later and pass `NamedWaitHandleOptions.None` to opt into global scope. Alternatively, set the `System.Threading.Mutex.UnsafeDefaultMutexScopeGlobal` runtime configuration option to `true` in your `runtimeconfig.json`. This option applies on all affected platforms.

If your process runs as a UID with no user database entry, named mutex creation fails. This situation is common in containers started with `docker run -u <uid>` or Kubernetes `runAsUser`. Set `XDG_RUNTIME_DIR` to a writable directory owned by that user, or create a user account for the UID in the container image.

## Affected APIs

- <xref:System.Threading.Mutex.%23ctor(System.Boolean,System.String)>
- <xref:System.Threading.Mutex.%23ctor(System.Boolean,System.String,System.Boolean@)>
- <xref:System.Threading.Mutex.%23ctor(System.Boolean,System.String,System.Threading.NamedWaitHandleOptions)>
- <xref:System.Threading.Mutex.%23ctor(System.String,System.Threading.NamedWaitHandleOptions)>
- <xref:System.Threading.Mutex.%23ctor(System.Boolean,System.String,System.Threading.NamedWaitHandleOptions,System.Boolean@)>
8 changes: 8 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ items:
href: core-libraries/11/environment-tickcount-windows-behavior.md
- name: Math.Round and MathF.Round return correctly rounded results
href: core-libraries/11/math-round-digits.md
- name: Named mutexes default to user scope on Unix
href: core-libraries/11/named-mutexes-unix-default-scope.md
- name: NamedPipeServerStream with PipeOptions.CurrentUserOnly tightens Unix socket file permissions
href: core-libraries/11/namedpipeserverstream-unix-permissions.md
- name: Nullable.GetUnderlyingType throws for custom Type subclasses
Expand Down Expand Up @@ -168,6 +170,8 @@ items:
href: core-libraries/10.0/ldap-directorycontrol-parsing.md
- name: MacCatalyst version normalization
href: core-libraries/10.0/maccatalyst-version-normalization.md
- name: Named mutexes default to user scope on Unix
href: core-libraries/11/named-mutexes-unix-default-scope.md
- name: No default termination signal handlers
href: core-libraries/10.0/sigterm-signal-handler.md
- name: System.Linq.AsyncEnumerable included in core libraries
Expand Down Expand Up @@ -358,6 +362,8 @@ items:
href: core-libraries/9.0/inlinearray-size.md
- name: InMemoryDirectoryInfo prepends rootDir to files
href: core-libraries/9.0/inmemorydirinfo-prepends-rootdir.md
- name: Named mutexes default to user scope on Unix
href: core-libraries/11/named-mutexes-unix-default-scope.md
- name: New TimeSpan.From*() overloads that take integers
href: core-libraries/9.0/timespan-from-overloads.md
- name: New version of some OOB packages
Expand Down Expand Up @@ -524,6 +530,8 @@ items:
href: core-libraries/8.0/ldap-netstandard-apis.md
- name: Method builders generate parameters with HasDefaultValue=false
href: core-libraries/8.0/parameterinfo-hasdefaultvalue.md
- name: Named mutexes default to user scope on Unix
href: core-libraries/11/named-mutexes-unix-default-scope.md
- name: Package part URIs are now compared case-insensitively in System.IO.Packaging
href: core-libraries/8.0/system-io-packaging-case-insensitive-uri.md
- name: ProcessStartInfo.WindowStyle honored when UseShellExecute is false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static void TestCars1()
// used in the definition of ShowDetails in the ConvertibleCar
// class.

Car car2 = new ConvertibleCar();
ConvertibleCar car2 = new ConvertibleCar();
car2.DescribeCar();
System.Console.WriteLine("----------");

Expand Down
29 changes: 22 additions & 7 deletions docs/framework/data/adonet/ado-net-code-examples.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
title: "Code examples"
description: "These examples show .NET Framework programmers how to retrieve data from a database by using ADO.NET data providers and ADO.NET Entity Framework."
ms.date: "03/30/2017"
title: "Code Examples"
description: "Retrieve data with ADO.NET data providers, including Microsoft.Data.SqlClient for SQL Server, and explore .NET Framework Entity Framework examples."
ms.date: "10/19/2026"
ai-usage: ai-assisted
dev_langs:
- "csharp"
- "vb"
Expand All @@ -13,7 +14,7 @@ The code listings on this page demonstrate how to retrieve data from a database

- ADO.NET data providers:

- [SqlClient](#sqlclient) (`System.Data.SqlClient`)
- [SqlClient](#sqlclient) (`Microsoft.Data.SqlClient`)

- [OleDb](#oledb) (`System.Data.OleDb`)

Expand All @@ -37,12 +38,26 @@ The following code listings demonstrate how to retrieve data from a database usi

### SqlClient

The code in this example assumes that you can connect to the `Northwind` sample database on Microsoft SQL Server. The code creates a <xref:System.Data.SqlClient.SqlCommand> to select rows from the Products table, adding a <xref:System.Data.SqlClient.SqlParameter> to restrict the results to rows with a UnitPrice greater than the specified parameter value, in this case 5. The <xref:System.Data.SqlClient.SqlConnection> is opened inside a `using` block, which ensures that resources are closed and disposed when the code exits. The code executes the command by using a <xref:System.Data.SqlClient.SqlDataReader>, and displays the results in the console window. If you're using `System.Data.SqlClient`, you should consider upgrading to `Microsoft.Data.SqlClient` as it's where future investments and new feature developments are being made. For more information, see [Introducing the new Microsoft.Data.SqlClient](https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient).
To access SQL Server with ADO.NET, use the [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) NuGet package. The following C# and Visual Basic projects target .NET 10 and .NET Framework 4.8.1 and reference this package. Use the .NET 10 SDK to build the projects.

The examples query the `dbo.Products` table in the `Northwind` sample database. The <xref:Microsoft.Data.SqlClient.SqlCommand> selects products with `UnitPrice` greater than 5. The <xref:Microsoft.Data.SqlClient.SqlParameter> specifies the price as <xref:System.Data.SqlDbType.Money>. The <xref:Microsoft.Data.SqlClient.SqlDataReader> reads the product ID, unit price, and product name in descending order of unit price. The `using` blocks (`Using` in Visual Basic) dispose of the reader, command, and <xref:Microsoft.Data.SqlClient.SqlConnection>.

Before you run either project, set the `SQL_CONNECTION_STRING` environment variable in the process that launches the example. For example, on Windows with integrated authentication, use the following PowerShell command. Replace `<server>` with your server name and configure the server with a certificate that the client trusts.

```powershell
$env:SQL_CONNECTION_STRING = 'Server=<server>;Database=Northwind;Integrated Security=true;Encrypt=true;TrustServerCertificate=false'
```

For other authentication options, see [Connection string syntax](/sql/connect/ado-net/connection-string-syntax).

[!INCLUDE [managed-identities](../../../includes/managed-identities.md)]

[!code-csharp[DataWorks SampleApp.SqlClient#1](../../../../samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SampleApp.SqlClient/CS/source.cs#1)]
[!code-vb[DataWorks SampleApp.SqlClient#1](../../../../samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SampleApp.SqlClient/VB/source.vb#1)]
To use the driver's Microsoft Entra ID authentication modes, including managed identity, also install the `Microsoft.Data.SqlClient.Extensions.Azure` NuGet package. For setup instructions, see [Microsoft Entra ID authentication](/sql/connect/ado-net/sql/azure-active-directory-authentication).

:::code language="csharp" source="./snippets/ado-net-code-examples/csharp/Program.cs" id="SqlClient":::
:::code language="vb" source="./snippets/ado-net-code-examples/vb/Program.vb" id="SqlClient":::

From either snippet project directory, run `dotnet run --framework net10.0`. On Windows with .NET Framework 4.8.1 installed, use `dotnet run --framework net481`.

### OleDb

Expand Down
7 changes: 5 additions & 2 deletions docs/framework/data/adonet/ado-net-overview.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
title: "Overview"
description: Read an overview of ADO.NET in .NET Framework and read about resources for more detailed explanations and examples.
ms.date: "03/30/2017"
ms.date: "10/19/2026"
ai-usage: ai-assisted
ms.assetid: ee3bc1d8-11db-4be4-89eb-c708cf04117d
---
# ADO.NET Overview

ADO.NET provides consistent access to data sources such as SQL Server and XML, and to data sources exposed through OLE DB and ODBC. Data-sharing consumer applications can use ADO.NET to connect to these data sources and retrieve, handle, and update the data that they contain.

For new SQL Server applications, use the [Microsoft.Data.SqlClient](https://www.nuget.org/packages/Microsoft.Data.SqlClient) NuGet package. For runnable C# and Visual Basic examples, see [ADO.NET code examples](ado-net-code-examples.md#sqlclient).

ADO.NET separates data access from data manipulation into discrete components that can be used separately or in tandem. ADO.NET includes .NET Framework data providers for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, placed in an ADO.NET <xref:System.Data.DataSet> object in order to be exposed to the user in an ad hoc manner, combined with data from multiple sources, or passed between tiers. The `DataSet` object can also be used independently of a .NET Framework data provider to manage data local to the application or sourced from XML.

The ADO.NET classes are found in System.Data.dll, and are integrated with the XML classes found in System.Xml.dll. For sample code that connects to a database, retrieves data from it, and then displays that data in a console window, see [ADO.NET Code Examples](ado-net-code-examples.md).
The ADO.NET classes included in .NET Framework are found in System.Data.dll, and are integrated with the XML classes found in System.Xml.dll. The separately distributed SQL Server provider uses Microsoft.Data.SqlClient.dll. For sample code that connects to a database, retrieves data from it, and then displays that data in a console window, see [ADO.NET Code Examples](ado-net-code-examples.md).

ADO.NET provides functionality to developers who write managed code similar to the functionality provided to native component object model (COM) developers by ActiveX Data Objects (ADO). We recommend that you use ADO.NET, not ADO, for accessing data in your .NET applications.

Expand Down
Loading
Loading