Source Code Management and Database Deployment - Deploying Create Scripts in Visual Studio .NET
(Page 9 of 9 )
Create scripts generated in Visual Studio .NET can also be “glued” together and deployed on other servers:
- Select the Create Scripts folder in Solution Explorer, and then select Project | Create Command File.
- Set the Name of Command File and move all or just some of the scripts in the Available Scripts list to the list of Scripts To Be Added To The Command File.
- If you have moved some of the table files (TAB) that have data files (DAT) associated with them, the Add Data button becomes available. Click the button and the program prompts you to confirm associations between files:
- You probably do not need to change anything, so just click OK and the program returns you to the previous screen.
- Click OK again and the program generates a command file (or batch file) that can be used to execute all Create scripts on any server (see Figure 11-9).

Figure 11-9. Command file for deploying Create scripts
Incremental Build: Traditional Approach Whichever method you choose for performing a full build of the database, you will eventually need to deploy design changes and hotfixes while preserving data in the database. Such changes can even accumulate over time. Typically, code changes for procedures can simply be executed in their latest form against the production database, but changes to the database structure (tables) must be implemented in such a way that they preserve data.
prBatchExec is very useful for deploying incremental changes on the database server. Individual changes to database objects can be grouped by defect number or version number (see Figure 11-10).
It is especially useful to run the process as a transaction in this case. If an unexpected error occurs during the deployment, it is preferable to roll back all the changes, leaving the production system intact.
TIP
Once you assemble deployment scripts, it is critical to perform sufficient unit testing. You can run the scripts against a new server or a new instance on the existing server and test the changes. You should repeat the deployment, fixing issues that you find, until it runs without a glitch. The ultimate test is whether the application can work with the database system without additional intervention.

Figure 11-10. Deployment script for incremental build
Incremental Build in Visual Studio .NET Alternatively, you can create incremental scripts in Visual Studio .NET. In this case, you create Change scripts and manage them in the folder of the same name (in Solution Explorer). You should again create a command file, but you should probably name it differently. You will use the same techniques and methods that have already been described regarding the full build in the earlier section “Scripting Data in Visual Studio .NET.”
TIP
You should pay special attention to avoid mixing versions of files and to execute database changes in the right order. It is a good idea to add sequential numbers or the date and time at the beginning of filenames. You can store different releases in different folders, or you can have different command files if you keep all change scripts in the same folder. When you are done, test, test, and test again.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from SQL Server 2000 Stored Procedure & XML Programming, second edition, written by Dejan Sunderic (McGraw-Hill/Osborne, 2004; ISBN: 0072228962). Check it out at your favorite bookstore today. Buy this book now.
|
|