dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.14k stars 301 forks source link

Set `Application Name` to calling resource name on SQL Server Connection Strings #4124

Open afscrome opened 2 weeks ago

afscrome commented 2 weeks ago

The Application Name property on a SQL Server connection string adds an application name to the connection to SQL. This can be very useful if running SQL Profiler with multiple applications connecting to the same database as it allows you to identify what application a query originated from.

For example, if two resources api and worker both use the same database, the connection string in api would be

Server=127.0.0.1;User ID=sa;Password=***;TrustServerCertificate=true;Database=MyDb;Application Name=api

But in worker, the connection string would be:

Server=127.0.0.1;User ID=sa;Password=***;TrustServerCertificate=true;Database=MyDb;Application Name=worker
davidfowl commented 2 weeks ago

Related to https://github.com/dotnet/aspire/issues/2111. To make this work though we probably need an overload WithReference for the SQL server resource for these additional operations.