EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Document named connection string format

Open SetTrend opened this issue 4 years ago • 1 comments

In DbContext in dependency injection for ASP.NET Core it reads:

options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection"));

I couldn't find documentation on the name parameter of this connection string.

Is this a typo or does this connection string parameter exist?

If it exists, I propose to add corresponding explanation about the behaviour of this connection string parameter to, e.g., Connection Strings, or Configuration in ASP.NET Core.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

SetTrend avatar Feb 03 '21 17:02 SetTrend

If you use this connection string syntax and provide a connection string name that doesn't exist, the following exception is thrown:

System.InvalidOperationException: A named connection string was used, but the name 'x' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application. See https://go.microsoft.com/fwlink/?linkid=850912 for more information.

That linked page contains only very minimal information about the name=x syntax. And the C# code sample that is shown after that syntax is mentioned doesn't even use it.

Please expand the documentation. What is the difference between those methods? Which method is preferred?

Related: dotnet/efcore#8641

cremor avatar May 15 '23 13:05 cremor

Fixed in 473282b043408a10b2d8f5797dbfaf258ee28431

AndriySvyryd avatar Dec 06 '24 01:12 AndriySvyryd