Warum wird der Aspire MySQL -Dienst nicht entdeckt?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Warum wird der Aspire MySQL -Dienst nicht entdeckt?

Post by Anonymous »

Ich versuche, Aspire in meinen Entwicklungsworkflow zu integrieren, und die ASP.NET-Kernanwendung nicht mit der MySQL-Datenbank verbinden.

Code: Select all

var mysql = builder.AddMySql("db")
.WithEndpoint(port: 3306, targetPort: 3306, name: "mySqlPort")
.WithLifetime(ContainerLifetime.Persistent)
.WithInitBindMount("../sql/", true)
.WithDataVolume();
< /code>
builder.AddProject
("graphql")
.WaitFor(mysql)
.WithEnvironment("ConnectionStrings__FooContext",
"Server=db;Database=Foo;User=root;Password=aVerysecretPasswordIndeed;");
< /code>
And the GraphQL's section:
var builder = WebApplication.CreateSlimBuilder(args);
builder.AddServiceDefaults();

builder.Services.AddKeyedSingleton(DependencyInjectionKeys.FooContextOptionsBuilderKey, (sp, _) =>
{
var connectionString = builder.Configuration.GetConnectionString(nameof(FooContext));
if (string.IsNullOrEmpty(connectionString))
{
//omitted; get it from somewhere else
connectionString = $"server={dbHost};port={dbPort};database={dbName};user={dbUser};password={dbPassword};";
}

// fails here,
// Unable to connect to any of the specified MySQL hosts
var serverVersion = ServerVersion.AutoDetect(connectionString);

return (options) =>
{
options.UseMySql(connectionString, serverVersion, o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery))
.ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))
.EnableSensitiveDataLogging(false)
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrackingWithIdentityResolution);
};
});
< /code>
I've verified, that connectionString
ist in der Tat der gleiche wie der im Apphost konfigurierte, wenn es die Zeilenserverversion erreicht.Autodetekte (ConnectionString); . /> (Bitte ignorieren Sie die "Geheimnisse" vorerst. Ich werde damit umgehen, sobald die Konnektivität wie beabsichtigt funktioniert.) < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post