Reputation: 7578
I have 4 sql scripts that I want to run in a DACPAC in PostDeployment, but when I try to build the VS project for 3 of them I get this error:
Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
The scripts contain only INSERT
statements in different tables on the DB. And all of them are structured like so
IF NOT EXISTS (SELECT 1 FROM dbo.Criteria WHERE Name = 'Mileage') INSERT INTO dbo.Criteria(Name) VALUES ('Mileage'); only on different tables and with different data.
My question is why is VS complaining about 3 of them when all the scripts are the same in terms of syntax and operations?
PS: Adding 'GO' between statements as the error suggests doesn't do anything.
Upvotes: 180
Views: 77108
Reputation: 3777
This can happen when copy/pasting files from another project.
For me, I copied a post deployment script and then included it in the project via the Solution Explorer. The problem with including it this way is that it doesn't know it's a Post Deployment script so you have to change the properties yourself. Just click on the file, press F4, and then set the Build Action to the proper Build Action.
Upvotes: 0
Reputation: 8665
I ran into this error when using SQL Server Data Tools and it was because I had a post-deployment script that was added to the project wrong.
In the project file, any database objects should have elements like
<Build Include="dbo\tables\mytable.sql"/>
But scripts should have
<None Include="myscript.sql"/>
However I added my script file, it ended up with a Build
tag instead of a None
. Changing it to None
fixed the error.
Upvotes: 11
Reputation: 2543
Regardless this seems to be pretty old I stuck for some hours with that as well and I think this way could be helpful for many.
In Database project
, files set as Build
are considered as Database structure so just one statement is allowed in such file by design. Go
nor any other batch terminator will change that behavior, that message is just mistake.
More info here.
There is lot of other build options for files in such project.
For your case it seems that PostDeploy
. In such file you could have various commands like inserts
etc.
Then you can use output of Database project as dacpac file for Data-Tier DB applications (Otherwise it's not included).
Upvotes: 19
Reputation: 7578
I have found the problem. When I added the file in VS I forgot to set Build Action = None
from the file properties. So changing that fixed the problem and the project now compiles.
Upvotes: 471
Reputation: 2715
Remove the ;(semi-colon) from last of each statement and I am not sure but GO is not required between above insert statements.
Upvotes: -2