microsoft / microsoft/aspire

Add a database resource property with real connection string

Open
#14,681 7 comments 0 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

We use the "Connection string" (`resource.connectionString`) property to create a connection to the running database. Unfortunately, if a user hasn't specified the exact port (e.g. `builder.AddMySql("mysql")`), the port in the connection string will be different each time it is restarted, even for the `Persistent` lifetime. Thus, the container port doesn't change, but the port in the "Connection string" property does. As far as I understand it, this happens because of the [proxy](https://aspire.dev/fundamentals/networking-overview/). The disadvantage of this is that the user could not connect to the database after stopping Aspire, because the proxy was gone (in addition, we have to recreate the connection after each restart).

Image

### Describe the solution you'd like

I was wondering if you could add an additional technical property to the resource with a real connection string that would include the port from the database container rather than the proxy. This would be very helpful for us. Thank you in advance!

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by tracing how resource.connectionString is produced for database resources and how the proxy selects its port, then inspect the resource model or entry points that expose technical properties. Done means a separate connection string uses the database container's port rather than the proxy port and remains usable after Aspire stops.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.