aspire: Aspire SQL component connection fails when running a query
When I configure the Aspire SQL component using the steps in the readme, the connection fails when attempting to execute a query with this error in the C# code:
SqlException: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An established connection was aborted by the software in your host machine.)
I also see this error in the container logs: ERROR: Unable to set system administrator password: Password validation failed. The password does not meet SQL Server password policy requirements because it is not complex enough. The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols…
I have attempted to resolve this issue by deleting and repulling the latest image/container, and by adding Trusted_Connection=true to the connection string. @eerhardt was also able to reproduce this issue.
Apphost code:
var builder = DistributedApplication.CreateBuilder(args);
var sql = builder.AddSqlServerContainer("sql").AddDatabase("sqldata");
var myService = builder.AddProject<Projects.AspireSQL>("aspiresql")
.WithReference(sql);
builder.Build().Run();
Web app code:
builder.AddSqlServerClient("sqldata");
Sample queries:
@inject SqlConnection connection
@code {
protected override async Task OnInitializedAsync()
{
connection.Open();
using(SqlCommand command = new SqlCommand("CREATE TABLE Persons (ID int NOT NULL PRIMARY KEY IDENTITY, FirstName varchar(255), LastName varchar(255));", connection))
{
command.ExecuteNonQuery();
}
}
}
var c = _serviceProvider.CreateScope().ServiceProvider.GetRequiredService<SqlConnection>();
_logger.LogCritical($"got {c}");
c.Open();
using (var cmd = new SqlCommand("select 1", c))
{
cmd.ExecuteScalar();
}
@mitchdenny are you able to assist with this?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (12 by maintainers)
I already have that fix locally and am still seeing the same error @alexwolfmsft shows above. But you need to actually issue a command: