Filename missing in the error message
Closed this issue ยท 14 comments
When error occurs in project, the filename of "what file had error" would be important information to see in the error info.
SQL71006 Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
Background
I'm using this with a database with around hundred tables, and merge constantly branches of different SQL schemas.
Here is an example, where things go wrong, because automatic merge doesn't understand to add a GO
statement:
It would be very helpful to tell which of the modified 30+ files was the one that had the merge-error.
Workaround
Create old-fashion .sqlproj file next to this project and include the files there as well.
When you compile that, it will actually tell which file has the error.
I have the same issue. After the tweet bij @ErikEJ I thought, let's try and use this and I moved alle my .sql files from the existing .sqlproj to this new project style. At first I got a lot problems when the Analyzer was on (will open an issue on that) and now I still have this one. The .sqlproj processed the same files without problem, and because the error does not give me any clue where to find the problem I have to resort to binary split removing files to pinpoint the problem file.
Edit: I forgot to set Build Action = None on all those system data and pre/post deployment scripts but that did not solve the issue either. Not sure this is needed
@Thorium and @jbennink Unsurprisingly, we will be happy to help you improve this experience, but a small project that demonstrates the issue is needed to proceed.
After settings all pre/post deplyment scripts to Build action=none it still did not work. But when I removed a almost all files and then added them is small increments I ended up with a working project. I then removed everything again, re-added the original files from the .sqlproj, changed buildaction=none and it worked immediately. I must have somehow messed something up. [I can now continue testing]
I expect you can reproduce the original issue by removing any necessary "GO" keyword in any of your existing project.
For example table-creations-scripts have lot of "GO"s if you use indexes or descriptions.
@Thorium I see this in the build output:
1>Adding C:\Code\Github\EFCorePowerTools\test\ScaffoldingTester\Database\dbo\Procedures\Procedure1.sql to the model
1>Adding C:\Code\Github\EFCorePowerTools\test\ScaffoldingTester\Database\dbo\Tables\Logger.sql to the model
1>Adding C:\Code\Github\EFCorePowerTools\test\ScaffoldingTester\Database\dbo\Tables\Table1.sql to the model
1>Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
1> ---> Microsoft.SqlServer.Dac.Model.DacModelException: Add or update objects failed due to the following errors:
1>EXEC : error SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
...and a stacktrace:
1> at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.ThrowIfModelErrorsExist(String errorMessage)
1> at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.DoAddOrUpdateObjects(String inputScript, String sourceName, TSqlObjectOptions options)
1> at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.AddOrUpdateObjects(String inputScript, String sourceName, TSqlObjectOptions options)
1> at Microsoft.SqlServer.Dac.Model.TSqlModel.AddOrUpdateObjects(String inputScript, String sourceName, TSqlObjectOptions options)
1> at MSBuild.Sdk.SqlProj.DacpacTool.PackageBuilder.AddInputFile(FileInfo inputFile) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/PackageBuilder.cs:line 80
1> at MSBuild.Sdk.SqlProj.DacpacTool.Program.BuildDacpac(BuildOptions options) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/Program.cs:line 145
1> --- End of inner exception stack trace ---
1> at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
1> at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
1> at System.Delegate.DynamicInvokeImpl(Object[] args)
1> at System.Delegate.DynamicInvoke(Object[] args)
1> at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
1> at System.CommandLine.Parsing.ParseResultExtensions.InvokeAsync(ParseResult parseResult, IConsole console)
1> at MSBuild.Sdk.SqlProj.DacpacTool.Program.Main(String[] args) in /home/runner/work/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj/src/DacpacTool/Program.cs:line 80
1> at MSBuild.Sdk.SqlProj.DacpacTool.Program.<Main>(String[] args)
Processing stops after the first error
I am working on an improvement, so processing of files will continue and all errors be reported.
As this is F# project, it's fsproj and not csproj but the file extension shouldn't matter, it's just sql inside anyway.
Thanks!