Use Invoke-DbaQuery instead of ExecuteNonQuery for long batches to avoid issues on AppVeyor#10149
Conversation
|
agreed, thank you 🙏🏼 I was curious and asked Claude to do some research as to why it happens and the answer sounds plausible. Here's the TL;DR: Why it fails on AppVeyor: SMO's Why the event log explodes: When Fix both problems at once: Replace SMO foreach ($batch in $batches) {
try {
$cmd = $server.ConnectionContext.SqlConnectionObject.CreateCommand()
$cmd.CommandText = $batch
$cmd.CommandTimeout = 300
$null = $cmd.ExecuteNonQuery()
} catch {
$msg = $_.Exception.Message.Substring(0, [Math]::Min($_.Exception.Message.Length, 500))
Stop-Function -Message "Failed to install stored procedure: $msg" -Continue -Target $instance
}
}This eliminates the BatchParser.dll dependency entirely and truncates error messages so they never overflow the event log. No more chasing environment-specific DLL issues across CI platforms. |
|
Then we should change our methods |
The root cause is still unknown, but long batches trigger the error "Log entry string is too long. A string written to the event log cannot exceed 32766 characters." to be raised on AppVeyor and maybe other CI pipelines.
I can not reproduce the issue in my lab and I talked a lot with different LLMs without getting to the root cause.
So the best way is to run the code through our command Invoke-DbaQuery. That adds some overhead but on the other hand takes care of splitting the SQL into batches.
Only four of our commands use long batches, so I changed only those.
For more details see #10145.