-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aspire SQL component connection fails when running a query #1168
Comments
I think this is a dupe of #971 which is already fixed for preview.2 Can you try using latest daily builds of Aspire packages/workload? |
I already have that fix locally and am still seeing the same error @alexwolfmsft shows above. But you need to actually issue a command: var c = _serviceProvider.CreateScope().ServiceProvider.GetRequiredService<SqlConnection>();
_logger.LogCritical($"got {c}");
c.Open();
using (var cmd = new SqlCommand("select 1", c))
{
cmd.ExecuteScalar();
} |
Note also this is a different error message than #971
|
Can you try running the sample I added to dotnet/aspire-samples this week? |
I ran the sample at https://github.com/dotnet/aspire-samples/tree/main/samples/VolumeMount and that worked. Then I went back to my repro app. I was executing a command at startup of OrderProcessor, which was failing. I'm assuming because the DB server hadn't started up yet (which sort of makes sense given the error message). I moved the code to be on a button on the website, and that worked to connect to the DB and execute a command. @alexwolfmsft is this the same problem you are having? |
@eerhardt and @DamianEdwards a few things here: I was able to get the volumemount sample working, and then I retrofitted that setup back onto a simple out of the box solution like the one in my original issue description. I was able to get it working, but with some caveats:
Shouldn't the default behavior set a secure password to keep that parameter optional? If I set my own stronger password in user secrets and pass it into the method, this issue is resolved using the following code:
|
The SQL generated password issue is already fixed for preview 2. Correct on the point about volumes and managing the state. In our samples that use a database and EF, we either have code that ensures the database is updated on each launch, or we use a persistent volume and rely on the EF Core middleware to provide the developer a UX for running migrations the first time. |
Thanks, I remember now that the first one was addressed by #971. |
Following up after more experimentation - is there a sample somewhere showing how to initially create the database in the container if you're not using Entity Framework? It seems like the injected SqlConnection is already setup to point to a specific database, in this case aspiredb: var sql = builder.AddSqlServerContainer("sql", sqlpassword).AddDatabase("aspiredb"); The injected SqlConnection works if the database already exists in the container, but it seems as though you can't use an injected SqlConnection to actually create the database if it doesn't already exist because its already pointing to a specific db. Potential work around might be to run a separate startup script with a different connection string - is there an example of how to handle this scenario? Maybe I am misunderstanding something here. |
Nope. Today all our samples rely on EF to create the database if it doesn't exist already. |
@alexwolfmsft In your sample, you mention for Web app code:
However, I noticed that AddSqlServerClient is an extension method for IHostApplicationBuilder. Did you manually revert the template's default WebApplicationBuilder, to use the older IHostApplicationBuilder. |
|
Right. I shouldn't have said "old". But my question is, in the aspire template, the web app is initialized with WebApplicationBuilder. So to use AddSqlServerClient, should we switch it to use IHostApplicationBuilder. Shouldn't there be an extension extension method for adding Sql Client to WebApplicationBuilder? |
Yes, |
Note we have a sample now that shows how to configure the various supported database containers to be initialized using their integrated features: https://github.com/dotnet/aspire-samples/tree/main/samples/DatabaseContainers |
Given the original issue reported here was about password generation for the SQL resource type, and that was resolved in preview 2 ... we can go ahead and close this issue unless it is still a problem? |
Closing ... reopen if necessary. |
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:
Web app code:
builder.AddSqlServerClient("sqldata");
Sample queries:
@mitchdenny are you able to assist with this?
The text was updated successfully, but these errors were encountered: