In order to successfully publish your project, it must first be able to build successfully.
Start by building your project. Right-click the project and select “Build”.
If the build is successful, the project can be published.
You may want to create a folder within your project to store saved Publish Profiles. These can be used later to easily publish the project to your servers.
Creating Publish Profiles
Right-click the project and select Publish. This will bring up the Publish Database dialog.
Choosing to publish or opening a saved publish profile will initiate a build of the project.
Choose your target database, set your advanced options (similar to Schema Compare options), and choose the “Save Profile As” option to save this to a location within your project. Selecting the “Add profile to project” option will create the publish profile in the root of the project. You may wish to either move the file to a folder storing all of your publish profiles or, if you saved it without adding to the project, show all files of the project so you can include the file in the project.
Some options you may want to consider:
“Always re-create database” – this will re-create the database. Any data in the database will be lost.
“Block incremental deployment if data loss might occur” – If there are any changes that could result in the publish action failing because of data loss, this option will stop the script from running.
“DROP objects in target but not in project” – This will remove anything in the database that doesn’t exist in the project. Useful if you want consistency, but you may want to ensure this isn’t checked if there could be objects in the database that were created, but didn’t make it to the project.
Under the “Advanced Deployment Options”
Allow Incompatible Platform – Useful if you may publish to a different version of SQL Server than the one specified in the project
Include transactional scripts – Will run the entire update operation as a transaction. If any one part fails, the transaction will roll back. If you have cross-database dependencies, selecting this option could result in no changes being published if you’re publishing to a new server. For a new publication, you may want to de-select this option to ensure a successful deploy of what can be published.
Script state checks – This option will ensure that the publish action will only work on the specified server and database.
Verify deployment – Checks the database and project before publishing to try to ensure there are no changes that will cause problems with the publication such as missing data for a foreign key.
Using Publish Profiles
Once you’ve set up your publish profiles, you can easily use these to push changes to that server and database without needing to specify additional parameters. The easiest way to use them is to double-click the Publish Profile within the project and choose to either “Generate Script” or “Publish”.
Generate Script will generate a script for you to use to update the target at a later time (run in SQLCMD mode).
Publish will immediately attempt to push the changes to the target.
You can also use these at a later point to push changes through the SQLPackage.exe command line.
To publish your package through a command line we use something like the following:
You can override quite a few of the default settings through various command line arguments. This includes source, target, and variables. You can find a full list of the command line arguments at the SQL Package reference online.
Jenkins Automation for CI
We use Jenkins at my current workplace and set up a Jenkins job to do the following (With thanks to Matthew Sneeden for the assistance.):
Get the latest from our mainline repository
Build each SQLProj file.
Building the SLN file will result in also attempting to publish the database
I’ve been working with SQL Server for quite some time. Along the way, I’ve learned quite a few things and realized that I won’t ever know everything about SQL Server. I intended to keep growing and learning to be able to do my job well and share my experiences with others.
I currently work for a Health-related non-profit based in Boise as a Database Architect.