In the most recent installments of our series dedicated to SQL Server 2005 Express Edition, we have discussed the User Instance mechanism, presenting its unique characteristics and providing examples demonstrating its behavior. We have also described the role of Visual Basic 2005 Express Edition in designing and implementing applications that utilize this functionality. In this article, we will focus on the process of deploying and maintaining user instance-based applications, which employs ClickOnce technology, designed to minimize the administrative burden of application lifecycle management in a distributed environment.
The wealth of capabilities of Visual Basic 2005 Express Edition goes beyond its programming features. Its graphical interface includes options that can be used for distribution and automatic updates of .NET applications (accessible in the same straightforward manner as development actions we have employed earlier to create our sample code). However, to explore their range fully, you should first ensure that your local system is running Internet Information Services (IIS) and File Transfer Protocol (FTP) server-side components, which give you the ability to post content to be downloaded by your clients. To accomplish this, launch the Add or Remove Programs applet from the Control Panel and select Add/Remove Windows Components icon in the resulting dialog box. If you are running one of Windows Server 2003 editions, highlight the Application Server entry in the list of items in the Windows Component Wizard page and click on the Details command button, which will subsequently display subcomponents of Application Server, including Internet Information Services. If you are using a Windows XP Professional system, you will find the Internet Information Services listed as one of the top level components on the first page of the wizard. In either case, once you locate and highlight the relevant entry, click on the Details command button, ensure that File Transfer Protocol (FTP) Service and World Wide Web Service are included in the installation, and continue with the wizard to its completion.
If you added the IIS component after you have set up Visual Basic 2005
Express Edition, then you should also apply the procedure described in
Microsoft Knowledge Base article 306005. This is relevant in
situations where you want to make your database applications available for
deployment via ASP.NET. In short, this involves running
aspnet_regiis.exe -i from a local folder
containing the most recent .NET Framework version (which in our case should be
designates the RTM release of .NET Framework 2.0). This step can be ignored if
IIS was already present when you installed Visual Basic 2005 Express Edition
(since its setup process automatically takes care of creating appropriate
ASP.NET application mappings).
Now that we have satisfied prerequisites of full ClickOnce functionality, let's briefly review its advantages. One of its most important benefits is making applications readily available to users without the need for administrative privileges or knowledge of setup options (installation is completed via a straightforward, one-step process). Equally important is the self-maintenance capability, facilitating incremental, centrally-controlled updates to all deployed instances of the application. Each installation functions as a self-contained entity, which eliminates potential conflicts due to overwriting shared components utilized by other software running on the same system. An additional factor that contributes to the superiority of the ClickOnce mechanism is its ability to leverage Code Access Security permissions in determining privileges required by its applications.
In general, ClickOnce applications can be distributed via file shares, Web or FTP sites, or removable media. Depending on your preferences, you can launch them directly from the source location or install them locally. Note however, that even in case of the latter, the setup process does not affect content of the Program Files folder or registry, since application files and settings are stored in a secure cache, allocated on a per-user and per-application basis. (In addition, appropriate entries are added to the user's Programs menu and Add or Remove Programs (or its Vista equivalent Program and Features) Control Panel applet.)
To examine implementation and configuration of these features, we will leverage the sample application, whose development process we have described in our previous article. Its characteristics related to ClickOnce functionality are accessible via the Project Properties menu item (in the Project top level menu of the Visual Basic 2005 Express Edition main interface). After you select it, you will be presented with the Project Designer window, with Publish section that contains the following list of options:
- "Publish Location (web site, ftp server, or file path)" textbox designates a location where the current project will be published as a ClickOnce deployable application. This can be a file system path (local or remote, using UNC notation) as well as Web or FTP site (based on URL link). The browse... command button gives you the ability to point to a desired target via the Open Web Site dialog box (from where you can choose among File System, Local IIS, FTP Site, or Remote Site categories). It is also possible to assign a value of "Installation URL (if different than above)" textbox, which is useful in situations where applications are initially published to a staging area.
- "Install Mode and Settings" mutually exclusive options allow you to dictate whether the application will be available only while the system is online or while both online and offline (i.e. when a source location where installation files reside is not reachable). In case of the latter, relevant files and settings are retained on the target system (in a secure, application-specific cache within the end-user's profile), application entry is included in the Add or Remove Programs applet in Control Panel, and its shortcut appears in the user's portion of the Start->All Programs menu. More granular configuration options are available via the following command buttons (and their corresponding dialog boxes):
- "Application Files" - gives you the ability to specify files to be included with the ClickOnce-deployable application and to define their role. For each entry, the dialog box displays the file name, its publish status, and download group (defining collections of files to be installed depending on arbitrary conditions). The publish status dictates an action that will take place during publishing, application version update, or automatic downloads to clients, and can be assigned one of four values:
- Data File - designates a file identified as data (which, in our case, includes our SQL Server 2005 Express Edition database and its log, since files with extensions .mdf and .ldf are automatically assigned this status). Based on this assignment, the file gets stored in an application-specific data directory (located within the end-user's profile).
- Include - indicates that the file (other than data) should be added to the publish location.
- Exclude - indicates that the file should not be added to the publish location.
- Prerequisite - prevents installation if the file is not already present on a target computer.
- "Prerequisites" - lists prerequisites of your application (which in our case include .NET Framework 2.0, Windows Installer 3.1, and SQL Server 2005 Express Edition) and allows you to create a setup program that installs them on the target computer if their presence is not detected (this results in setup.exe being added to the publish location). In addition, you can specify whether the prerequisites should be downloaded from their original source (vendor's web site), from the same location as the application, or from an arbitrary location you point to within a designated text box.
- "Updates" - dictates whether the application will be automatically checking for updates (as expected, this command button is disabled when "The application is available online only" option is selected). This can be configured to take place either before or after the application starts. While the former ensures that only the latest version of application is used, you might opt for the latter if the speedy application launch is your priority (to limit the possibility of running outdated code, schedule periodic update checks or specify the minimum required version).
- "Options" - contains other miscellaneous deployment settings, including a language in which the application is published, publisher and product names, URL that can be referenced when looking for support, name of deployment web page (set to publish.htm by default) with checkboxes that control whether to "Automatically generate deployment page after every publish" and "Open deployment page after publish", as well as the following:
- "Block application from being activated via a URL" - applies specifically to applications that were installed (rather than set up for online only use) from a Web site and determines whether a user is required to initiate the application via its Start menu shortcut or can access it by pointing at its original source. Note that if you decide to disable it, the application will launch automatically following its installation.
- "Use ".deploy" file extension" - enabled by default, assigns .deploy extension to application files (so .exe or .mdf become .exe.deploy and mdf.deploy) to prevent issues caused by download restrictions imposed on the Web server to which the application has been published.
- "Allow URL parameters to be passed to application" - provides the ability to use a portion of the URL associated with the location of the published application as an input parameter during its execution.
- "For CD installations, automatically start Setup when CD is inserted" - applicable to situations where removable media-based deployment is used; results in the addition of an Autorun.inf file to the root folder where application files are stored. This, in turn, triggers the setup process as soon as the media presence is detected on a target computer.
- "Verify files uploaded to a web server" - introduces an additional check during the publishing process, confirming that download of each application file works as intended.
- Publish version - consists of four integers, representing major, minor, build, and revision number, respectively. With "Automatically increment revision with each publish" checkbox, you can control whether every subsequent publication of a given application is considered an update, which, as we mentioned earlier, affects the installation process on a target computer that hosts its older release. Similarly, if you want to ensure that changes you made to the application are applied to its already deployed instances, increase its version number and take advantage of the application update options.
- "Publish Wizard" - launches the Publish Wizard (which you can also access using the Publish option from the Build menu in the main interface of Visual Basic 2005 Express Edition). The wizard handles the process of making installation files available via a local or remote file system path, or via a download from a Web or FTP site, (all you are required to provide is a target location).
- "Publish Now" - publishes the current application using settings in the Publish section of the Project Designer window (listed above).
In our next article of this series, we will look in more detail at the impact of some of these options on the application installation, deployment, and updates.