Link to home
Start Free TrialLog in
Avatar of true_soln
true_soln

asked on

How do you deploy Generated Database Deployment Script (.sql file) that was generated by vsdbcmd.exe

I using VSDBCMD to generate an upgrade script
It creates a ModifyScript.sql file that is the changes required to take Existing Database to match the schema of the UpdatedDatabase.dbschema file.

If you open the ModifyScript.sql file is show the script for the changes
But it has :servar lines in it, which when open in SQL Server Management Studio does not know what to do with these lines. So these files don't seem to be intended to run in Management studio.

So questions is:
  How do you deploy this .sql file using VSDBCMD ?

ECHO "Generating Database Deployment Script..."
vsdbcmd.exe /a:Deploy /cs:"Server=.\SQL2008;Integrated Security=true;Pooling=false" /dsp:Sql /script:ModifyScript.sql /model:"UpdatedDatabase.dbschema" /p:TargetDatabase="ExistingDatabse"
PAUSE

Open in new window

GO
:setvar DatabaseName "ExistingDatabse"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL\DATA\"
:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL\DATA\"

Open in new window

Avatar of Chris McGuigan
Chris McGuigan
Flag of Canada image

What you are seeing is SQLCMD code.

In SSMS, when in the Query window you should see a Query Menu, in that there is a SQLCMD mode. Select that and see how you get on?

Avatar of true_soln
true_soln

ASKER

Yes selecting SQLCMD mode works in Management studio

But how can you run this .sql file from cmd line, so can automate it ?

ASKER CERTIFIED SOLUTION
Avatar of Chris McGuigan
Chris McGuigan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I added /dd in to the options for VSDBCMD
And it deployed the changes in to the existing database and created the modifyscript.sql

So that is one way to update the existing schema,

Still just not sure how can execute the modifyscript.sql file from cmd.
If it can be done from management studio, how do you do it from cmd line ?


ECHO "Generating Database Deployment Script..."
vsdbcmd.exe /a:Deploy /dd /cs:"Server=.\SQL2008;Integrated Security=true;Pooling=false" /dsp:Sql /script:ModifyScript.sql /model:"UpdatedDatabase.dbschema" /p:TargetDatabase="ExistingDatabse"
PAUSE

Open in new window