InvalidOperationException "CommandText property has not been initialized" when creation script contains 2 consecutive GO statements
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
There is a bug in this code:
https://github.com/dotnet/aspire/blob/00728f0f3cda5868f90b9efd03d43b6ae3366a80/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs#L261-L268
When there are 2 consecutive lines with a "GO" statement in the creation script, the batchbuilder will be empty, which results in a
```
System.InvalidOperationException: BeginExecuteNonQuery: CommandText property has not been initialized
at Microsoft.Data.SqlClient.SqlCommand.ValidateCommand(Boolean isAsync, String method)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(CommandBehavior behavior, AsyncCallback callback, Object stateObject, Int32 timeout, Boolean inRetry, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject)
at Microsoft.Data.SqlClient.SqlCommand.<>c.b__193_0(AsyncCallback callback, Object stateObject)
at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
at System.Threading.Tasks.TaskFactory`1.FromAsync(Func`3 beginMethod, Func`2 endMethod, Object state)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQueryAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
at Aspire.Hosting.SqlServerBuilderExtensions.CreateDatabaseAsync(SqlConnection sqlConnection, SqlServerDatabaseResource sqlDatabase, IServiceProvider serviceProvider, CancellationToken ct) in /_/src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs:line 270
```
Contributor guide
Assessment
This issue has not been assessed yet.