3. Web Deploy Package
If you are building an
Autohosted application then the app package produced by Visual Studio
will contain a Web deploy package containing your app code and pages.
Web Deploy is a tool produced by Microsoft that can take Web deploy
packages and deploy the contents to an Internet Information Server
(IIS) enabled server. It is also a packaging format that can be used
for deploying to Azure. Because Autohosted apps use Azure, your code
and pages are packaged as a Web deploy package for automated deployment
to Azure when an Autohosted app is installed. When the app is
installed, SharePoint Online takes the Web deploy package included in
the app’s .app file and
automatically deploys it to Azure. This creates a running website with
your app’s code and pages in it. Additionally, SharePoint Online
creates a new client ID and client secret and sets up the app with it
so that the OAuth and API calls all work . Likewise, when the app is uninstalled, the website in Azure is
removed. This entire process is managed by SharePoint Online without
any user or developer involvement, hence the name Autohosted model.
If you take a look inside an .app file for an Autohosted app, you will find the Web deploy package contained within it packaged into a .zip file and named the same name as the app in Visual Studio with a “.web” appended. For example, SharePointAppPackage.Web.zip file shown the in the file list in Figure 2 is the Web deploy package.
4. Database Package
Like Web deploy packages a database package may be included in an Autohosted app’s .app package. This is commonly called a DACPAC because it’s a file with a .dacpac
extension, but it is the packaging name for the Data-tier Applications
technology (DAC for short, chosen because DTA was already taken),
introduced in SQL Server 2008 R2. Essentially a DACPAC is a packaging
format for databases.
For developers, Visual Studio supports building .dacpac
files with the SQL Server Database Project type. SQL Azure also
supports deploying DACPACs, hence the use of DACPACs in Autohosted app
packages.
In the same way code packages work, if SharePoint
Online detects a DACPAC in the app package it will extract it, create a
database in SQL Azure, and deploy the DACPAC. This, in turn, creates
the tables, relationships, and associated SQL objects needed in the
database to support the application.
A question you might be asking yourself at this
point is, “How does my SharePoint app know where the database is?”
SharePoint will replace a specially named connection string in your
app’s web.config file after the database has been set up and configured. To ensure this works correctly you must have a connection string property named SqlAzureConnectionString and configured in the app’s web.config file as follows:
<add key="SqlAzureConnectionString" value="Data
Source=(localdb)\MyDatabaseProjName;Initial
Catalog=AutohostedAppDatabase;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False" />
NOTE As of this writing, Microsoft has indicated that the use of the SqlAzureConnectionString configuration property is subject to change moving forward.
After you have the database connection string,
you can treat the database and access it like any other SQL Azure
database, and all the same data access and query techniques apply.
WARNING
When thinking about developing Autohosted applications, it is important
to consider the life cycle of an Autohosted app and the impact it has
on data stored in the SQL database. Like the Web deploy package for an
Autohosted app, the SQL database is also deleted after the app is
uninstalled. This causes data loss, and there is no way to get it back.