0

I have a batch file called dbcompare.bat, and I use it to run a tool that compares databases. I want to compare a bunch of databases, so I made a second batch file, let's call it dbcompare-all.bat, which calls dbcompare.bat for each database in turn.

My problem is that when I run dbcompare-all.bat, only the first database is compared; the other calls to dbcompare.bat don't seem to execute. Why is this? How can I fix it?

Here's the dbcompare-all.bat:

@echo off
rem syntax: dbcompare-all.bat sa password123
dbcompare.bat system db1 %1 %2
dbcompare.bat system db2 %1 %2
dbcompare.bat system db3 %1 %2
dbcompare.bat system db4 %1 %2
dbcompare.bat system db5 %1 %2
dbcompare.bat system db6 %1 %2

And here's the dbcompare.bat:

@echo off
rem syntax: dbcompare.bat system dbname sa password123
echo Platform is %1
echo Partner DB is %2
echo DB username is %3
sqlpackage /Action:Script /DeployReportPath:%1.%2.xml /DeployScriptPath:%1.%2.sql /TargetDatabaseName:%2 /TargetPassword:%4 /TargetServerName:%1.ourcompanyname.us /TargetUser:%3 /SourceFile:%1.dacpac > %1.%2.out.txt 2> %1.%2.err.txt
ekolis
  • 6,270
  • 12
  • 50
  • 101
  • 4
    Fun Fact: you used the word `call` (called calling, calls) exactly six times. That's exactly the number of times you have to use the `call` command (see @Magoo's answer). – Stephan Feb 22 '21 at 15:28

1 Answers1

3

It's all in your question title.

You are executing the batch file which transfers execution to the destination batch. When that batch ends, the entire process ends.

You need to do what you claim to do:

CALL dbcompare.bat system db1 %1 %2
CALL dbcompare.bat system db2 %1 %2
CALL dbcompare.bat system db3 %1 %2
...
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Oh, interesting. I remember VB also has a Call command, but it doesn't seem to actually do anything; the subroutine being called will return whether or not you use it. – ekolis Feb 23 '21 at 17:42