Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Friday, 31 July 2015

Deploy Azure DB via Web App – Using VS 2013 Release Management – Part 2 – Setup RM Component and Template to Deploy

In the Part 1 of this post, creating a web deployment package with dacpac, is explained. To deploy the dacpac to Azure DB via web deployment package, a Release Management template should be setup. The same component created in article “How to Deploy to Azure Websites with TFS build 2013 and VS Release Management 2013”, can be enhanced to deploy the database, using the dacpac file in web deployment package.
21
22 
In the Configuration Variables tab the newly added token __DemoAzureDBCon__ (adding the token in publish profile explained in Part 1) is set as a variable.
23
Next step is setting up an Azure DB. To do this create an SQL database in Azure management portal.
24
Select Create a new Azure DB server, to create a new DB server for Azure DB. Make sure to select Allow Azure services to access server option.
25
Database created in Azure with above options.
26
A web app in Azure is created to deploy the web application.
27
28
32
Copy the connection string (ADO.Net connection string) from the database connection strings and add it in the created web app settings, as a SQL Database connection.
28.1
Make sure to update the correct password to the connection string (Copied one has {your_password_here}).
Server=tcp:ch-demodbsvr01.database.windows.net,1433;Database=DemoAzureDB1;User ID=ch-dbsvradmin@ch-demodbsvr01;Password={your_password_here};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
28.2
In the Web App download the publish profile.
29
From the publish profile copy the values and set the parameters in the Release Management template.
30
  • WebAppName = Package zip file name (Package created with TFS build in Part 1).
  • PublishUrl = Publish Profile –> PublishUrl.
  • PublishUser = Publish Profile –> userName
  • PublishPassword = Publish Profile –> userPWD
  • AzureWebAppName = Publish Profile –> msdeploySite
  • DemoAzureDBCon = Publish Profile –> SQLServerDBConnectionString
31
With this template a release can be triggered using the build (Part 1).
33
Web Application gets deployed.
34

image
Database deployed with Web App.
35
Created Azure DB can be viewed in SQL Object Explorer in VS.
36
Allow the IP if prompt.
37
38
39

Tuesday, 28 July 2015

Deploy Azure DB via Web App – Using VS 2013 Release Management – Part 1 – Package SQL dacpac with Web Deploy Package in TFS Build

As explained in the post “How to Deploy to Azure Websites with TFS build 2013 and VS Release Management 2013” a tool can be created in VS 2013 Release management to deploy web sites to Azure. Below are the steps to deploy a azure database with the web application, using the same tool (enhanced to handle database deployments).
In the solution taken for as example a Web application project and a Database project created.
1
For demo purpose one table added to the database and created in localdb (db server provided with Visual Studio).
2
3
4
5
6

This database is added to the Web Application project by defining a connection string in the web.config file.
7
In the publish profile (for details on creating a publish profile for the web application refer the article here) database connection should be defined as a token understandable by the VS 2013 Release Management (__ as prefix and suffix).
8
Once this is published the required deployment packages created.
9
But the .dacpac file to deploy the db is not added to the web package zip file. It is required to get .dacpac inside the web package to deploy it with web application deployment.
10
In order to get the .dacpac file to web package change the publish profile (pubxml) content as shown below.
Current
11
Changes highlighted.
  • DB Connection object group enabled.
  • Default created “DbDacFx” object type is disabled.
  • Added new “DbDacFx” with dacpacAction Deploy and path set to relative path of the .dacpac file being built for the SQL project. Note that bin\debug path is set here which is not going to work with TFS builds.
12
Then there should be a project dependency added to build the SQL project before the web application project to make sure the availability of .dacpac file.
16
With the above change when the web application is published as a web deploy package, the .dacpac file gets included in it.
13
The next step is to get this packaged via TFS builds. As explained in the article here TFS build can be setup for this purpose with build arguments specified below.
/p:CreatePackageOnPublish=true /p:DeployOnBuild=true;PublishProfile="TFSAzureRelease"
14
As expected FS build fails with error, unable to find .dacpac file.
15
By changing the publish profile relative path to .dacpac file as below as will give a successful build.
17
18

Web deployment package in the drop now contains the .dacpac file.
20
Set parameter xml is created with the tokens added for DB connection.
19
In Part 2 let’s look at how to enhance the release management component, to deploy web application package (explained in article here), with the database .dacpac file to Azure DB.

Popular Posts