microsoft / microsoft/vscode-mssql

[Bug]: SQL71006 error when using GO inside direct script file, but not when included via post deploy with :r option

Open
#19,840 4 comments 0 reactions 1 assignee Claimed by @ssreerama View on GitHub
Area - SQL Project Bug User-filed
Dominant language
TypeScript
Stars
1.9k
Forks
610
Avg merge
2d 3h
Merged PRs (30d)
97

Description

### Description

When creating a new SQL Database Project (.sqlproj) and adding a .sql script file containing multiple batches separated by GO, the build fails with the following error
**Build error SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.**

However, if the exact same script is included using the :r directive (e.g. from a post-deployment script), the build succeeds without errors or warnings.

it's not clear to me if this is an issue in the sqlproject extension or from the underlying DACFX. Hoping someone from the team can repro and assign to the correct project.

### Steps to Reproduce

Create a new .sqlproj SQL Database project.

Add a file Script.Direct.sql with this content:

```
PRINT 'Start batch 1';
GO
PRINT 'Start batch 2';
GO
```
Add it to the project directly via the item group or “Add Existing Item”.

Build the project.

Build fails with:
SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.

To resolve:
Instead of including the script directly, create a post-deployment script like this:

`:r .\Post-Deployment\Script.Direct.sql`

And add this .sql as the post-deploy script in the project
Build succeeds with no errors or warnings, despite the GO batch separator.

### Affected Area

- [ ] Connection dialog
- [ ] Query results panel
- [ ] Query editor
- [ ] Object Explorer
- [ ] Table Designer
- [ ] Schema Compare
- [ ] Schema Designer
- [ ] Local container
- [ ] GitHub Copilot integration
- [ ] Query Plan Visualizer
- [x] Other (please describe below)

### If you selected "Other", please describe the affected area

SQL Project

### Environment Information

Microsoft.Data.Tools.Msbuild / DACFx version: 170.0.94

SQL Database Projects (VS/SDK): 1.5.3

Target platform: Azure SQL Database or SQL Server

### Confirmation

- [x] I have searched existing issues and couldn't find a match
- [ ] I want to work on this issue

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.