Offer Multiple Data Storage Options in the Same Package

The Web Platform Installer (WebPI) and the Web Deployment Tool (Web Deploy) UI in inetmgr both provide a way for packages to support offering multiple data storage options (such as a choice between SQL and MySQL) in the same package. Package creators can use parameter tagging to access this functionality, which is then surfaced to the end-user as a drop-down choice.

WebPI drop-down looks like this:

image

What tags do I use?

The current list of data storage options are: SQL Database, MySQL Database, SQLite, VistaDB, and Flat File. Each tag corresponds to a data storage option as noted in the following table for what will appear in the Web Deploy UI:

Tag

Drop-down option shown

Sql

SQL Database

MySql

MySQL Database

SQLite

SQLite

VistaDB

VistaDB

FlatFile

Flat File

No Database

Note that the “No Database” option will be shown if you use more than 1 database type.

How does it work?

You may already be familiar with using parameters to customize your application packages. If this idea is new to you, this page offers some good descriptions for several common parameter types used in applicaiton packages: http://learn.iis.net/page.aspx/722/reference-for-the-web-application-package/

For data storage – you will tag your database-related parameters, such as “Database Name” with one of the aforementioned database tags: SQL, MySql, VistaDB, SQLite, or FlatFile. If you use more than one of these database tags in your parameters.xml file, the Web Deployment Tool UI or Web Platform Installer will ask users importing the package which database type they would like to use.

The user will select their desired data storage type (such as “SQL Database”) and any other database-tagged parameters which do not have the selected tag (i.e. not “SQL”) will be ignored.

This is why you can offer multiple types of databases with, in some cases, overlapping parameters – because only 1 complete set will be used.

Note: This may not work out well for Web Deploy command line install (msdeploy.exe), particularly if your parameters overlap multiple database types – so make sure you only apply this parameter approach for packages that are meant to be installed using the UI.

What’s FlatFile?

Sometimes you want to offer data storage that isn’t related to a database – the type of tag for this is “FlatFile”. This is what you might use for data storage in a .txt file or .xml file as an alternative to a SQL database or other database type.

Show me an example!

Let’s say you want to offer a package that gives users the option of using either a SQL Database or a simple text file to store their application information. Your parameters.xml file might look something like this:

<parameters>

<!--1. Standard application path parameter indicates where to install the application-->

<parameter name="Application Path" defaultValue="Default Web Site/myCoolApp" tags="IisApp">

<parameterEntry kind="ProviderPath" scope="iisApp" match="Default\ Web\ Site/myCoolApp" />

</parameter>

<!--2. SQL Database-related parameters for use in the hidden connection string. All contain the "Sql" tag. These will only be shown if "SQL Database" option is chosen. -->

<parameter name="Database Server" defaultValue=".\SQLExpress" tags="DBServer, Sql" />

<parameter name="Database Name" defaultValue="myCoolApp_db" tags="DBName, Sql" />

<parameter name="Database Administrator" defaultValue="sa" tags="DBAdminUserName, Sql" />

<parameter name="Database Administrator Password" defaultValue="" tags="DBAdminPassword, Sql" />

<!--3. Hidden SQL connection string parameter uses the parameters above. Also tagged with "Sql". This parameter will only be used if "SQL Database option is chosen. --> 

<parameter name="Connection String" defaultValue="Data Source={Database Server};Database={Database Name};uid={Database Administrator};Pwd={Database Administrator Password}" tags="Hidden, Sql, SqlConnectionString">

<parameterEntry kind="ProviderPath" scope="dbFullSql" match="data\ source=\.\\SQLExpress;initial\ catalog=myCoolApp_db;user\ id=myCoolAppUser;pooling=False" />

</parameter>

<!--4. Hidden Flat File database parameter tagged with "FlatFile" tag. This file will only be copied if the "Flat File" option is chosen (rather than "SQL Database").-->

<parameter name="Flat File Database Location" defaultValue="{Application Path}/myCoolApp_data.txt" tags="FlatFile, Hidden">

<parameterEntry kind="ProviderPath" scope="contentPath" match="d:\\users\\iislab1\\desktop\\myCoolApp_data\.txt" />

</parameter>

</parameters>

On import in the Web Deployment Tool UI, you’d see these options – SQL Database, Flat File, or No Database:

image

If you choose SQL Database – you’ll get the SQL connection string related parameters on the parameters page, and the data storage file will not be copied over (that parameter is skipped because it doesn't have the selected database tag of "SQL").

If you choose Flat File, the file will be copied over, and you will not be asked for the connection string information parameters. For the Flat File choice, you also won’t be forced to select anything for the “Create new or use existing” option. This is grayed out when you choose the Flat File type.

clip_image002

So a user can make their choice, will only be presented with applicable parameters, and the unused parameters will be skipped. 

Voila!

If you're interested in making packages for the Application Gallery, you can check out these lovely resources for more information: http://learn.iis.net/page.aspx/605/windows-web-application-gallery-principles/ & http://learn.iis.net/page.aspx/578/package-an-application-for-the-windows-web-application-gallery/ .

1 Comment

Comments have been disabled for this content.