Figure 34: Viewing the server selection policy Adding a post-deployment script to the project You can specify actions that will take place after a data-tier application is deployed to an instance of SQL Server. You specify such post-deployment actions in the post-deployment script that resides under Scripts, under the Post-Deployment folder in Solution Explorer. To include Transact-SQL code in a post-deployment script, double-click the Script.PostDeployment.sql file and add code to the script using the editor. After changes are made, save the script to include the changes. Then, press F6 to build the solution. When working with post-deployment scripts, you should take several considerations and best-practices into account: In the first release of data-tier applications, the post-deployment script can be used to manipulate (for example, populate) data after project deployment. In addition, the script can be used to create objects that may not be in the initial release of applications. When you the solution to create a DAC package, the post-deployment script Script.PostDeployment.sql becomes part of the DAC package. When you work in Solution Explorer, it is recommended that you include all post-deployment commands in the Script.PostDeployment.sql script file. This is because only one file is included in the DAC package. In other words, you should not create multiple files. If you want to view the post-deployment script in the DAC package, it is recommended that you use the functionality, which is available on computers running the client tools for SQL Server 2008 R2. When a data-tier application is deployed the post-deployment script is not executed automatically against the target instance. In order to apply the script changes to the data-tier application, you must run and manually execute the script against the target instance and database used by the data-tier application. Visual Studio identifies a post-deployment script through the Build Action property associated with the script. To see the property, select the script in Solution Explorer and press F4 to set focus on the Properties window, and then find and review the Build Action property. For a script, the property value should be PostDeploy.
Figure 34: Viewing the server selection policy Adding a post-deployment script to the project You can specify actions that will take place after a data-tier application is deployed to an instance of SQL Server. You specify such post-deployment actions in the post-deployment script that resides under Scripts, under the Post-Deployment folder in Solution Explorer. To include Transact-SQL code in a post-deployment script, double-click the Script.PostDeployment.sql file and add code to the script using the editor. After changes are made, save the script to include the changes. Then, press F6 to build the solution. When working with post-deployment scripts, you should take several considerations and best-practices into account: In the first release of data-tier applications, the post-deployment script can be used to manipulate (for example, populate) data after project deployment. In addition, the script can be used to create objects that may not be in the initial release of applications. When you the solution to create a DAC package, the post-deployment script Script.PostDeployment.sql becomes part of the DAC package. When you work in Solution Explorer, it is recommended that you include all post-deployment commands in the Script.PostDeployment.sql script file. This is because only one file is included in the DAC package. In other words, you should not create multiple files. If you want to view the post-deployment script in the DAC package, it is recommended that you use the functionality, which is available on computers running the client tools for SQL Server 2008 R2. When a data-tier application is deployed the post-deployment script is not executed automatically against the target instance. In order to apply the script changes to the data-tier application, you must run and manually execute the script against the target instance and database used by the data-tier application. Visual Studio identifies a post-deployment script through the Build Action property associated with the script. To see the property, select the script in Solution Explorer and press F4 to set focus on the Properties window, and then find and review the Build Action property. For a script, the property value should be PostDeploy.
Data-tierAppsInSQLServer2008R2.docx