Skip to content

SqlServer Entityframework connectionstring not working as expected #2437

Answered by davidfowl
SaMaxNet asked this question in Q&A
Discussion options

You must be logged in to vote

In preview 3 you can just set it directly:

var builder = DistributedApplication.CreateBuilder(args);

var sql = new ConnectionString("sql");

var apiService = builder.AddProject<Projects.AspireDBTestApplication_ApiService>("apiservice")
    .WithReference(sql);

builder.AddProject<Projects.AspireDBTestApplication_Web>("webfrontend")
    .WithReference(apiService);

That will look for a connection string in the apphost's configuration.

In the preview 4, it'll look like:

var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddConnectionString("sql");

var apiService = builder.AddProject<Projects.AspireDBTestApplication_ApiService>("apiservice")
    .WithReference(sql);

Replies: 10 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by SaMaxNet
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
3 participants
Converted from issue

This discussion was converted from issue #2336 on February 26, 2024 19:21.