A connection string gives a client the configuration it needs to reach a resource. In an Aspire application, a resource name links a service’s configuration to a connection string supplied or generated by the AppHost. The service can resolve that name without keeping a separate copy of the value in its own settings. section 3.1 section 5.2.1
The source of the value depends on the resource:
- For an existing database, register `builder.AddConnectionString("database")` in the AppHost. Put the actual value under `ConnectionStrings:database` in the AppHost’s settings, then pass the resource reference to services that need it. section 3.1
- For a hosted resource, the connection string can be constructed from its endpoint. A MailDev resource implements `IResourceWithConnectionString` and builds an `smtp://` value from its SMTP host and port. section 2.7.1
Extracting an endpoint for Semantic Kernel
An Ollama model reference named `phi35` places a value under `ConnectionStrings:phi35`. The backend reads it with `builder.Configuration.GetConnectionString("phi35")`, uses `DbConnectionStringBuilder` to find its `Endpoint` value, and passes that URI to `AddOllamaChatCompletion`. If `Endpoint` is missing, it throws an `InvalidDataException` rather than registering a misconfigured client. section 5.2.1
DbConnectionStringBuilder csBuilder = new()
{
ConnectionString = phiConnectionString
};
if (!csBuilder.TryGetValue("Endpoint", out var ollamaEndpoint))
{
throw new InvalidDataException(
"Ollama connection string is not properly configured.");
}
The parser checks for the endpoint before the backend uses it. section 5.2.1






