Tutorial: Deploying A SQL Anywhere .NET Application Using ClickOnce PDF
Tutorial: Deploying A SQL Anywhere .NET Application Using ClickOnce PDF
W HI TE PA PE R
www.sybase.com
Contents:
Introduction ...................................................................................................................................... 2
Why deploy using ClickOnce? ..................................................................................................... 2
Prerequisites ................................................................................................................................. 2
Preparation ....................................................................................................................................... 3
Gathering the Database Engine Files .......................................................................................... 3
Creating batch file to run dbdsn.exe .......................................................................................... 3
Setting up the project ...................................................................................................................... 4
Deploying an Application ................................................................................................................ 9
Updating an Application ............................................................................................................... 16
Conclusion ....................................................................................................................................... 22
Principal Author
Ahmed Munye
Revision History
Version 1.0 - May 2012
Introduction
SQL Anywhere is a versatile database capable of integrating with a wide variety of development
environments, runs on various platforms, and is easily deployable using different methods. One way of
distributing a SQL Anywhere database application is by using Microsofts ClickOnce technology to deploy
Windows-based solutions.
While going through this tutorial, we will be deploying and installing a sample ADO.NET application
using the ClickOnce deployment method. We will then update the database runtime files and redeploy
the application.
If you are interested in learning about other methods of deploying a SQL Anywhere database application
(InstallShield, silent install, etc.), refer to the document Tutorial:Embedding SQLAnywhere in
Commercial Applications Requiring a Database available here:
http://www.sybase.com/detail?id=1093518.
Prerequisites
SQL Anywhere 12 or higher a free Developer Edition of SQL Anywhere is available here:
http://www.sybase.com/detail?id=1016644
Samples included in the SQL Anywhere installation (Default location is C:\Documents and
Settings\All Users\Documents\SQL Anywhere 12\Samples)
Latest SQL Anywhere 12 (or higher) Emergency Bug Fix (EBF) available here:
http://downloads.sybase.com/swd/summary.do?baseprod=144&client=ianywhere
Visual Studio 2010
Microsoft Internet Information Services (IIS) 6 or higher (only if you want to deploy the
application via web browser)
.NET Framework 3.5 or higher
OPTIONAL: Another computer or virtual machine image to deploy the application.
This paper was written for the Windows x86 platform, but is applicable to 64-bit systems as well.
Preparation
In this demonstration, we will be deploying the SQL Anywhere ADO.NET sample application
SimpleViewer that is included in the SQL Anywhere installation. We will also define a batch file to run
the Data Source utility (dbdsn.exe) to create an ODBC data source name for the demo database. We will
later modify the project to run the batch file before launching the application to eliminate end-user
setup procedures. Moreover, we will need to have Internet Information Services (IIS) installed (with the
default website) so that we can distribute the application via the localhost web address.
dbctrs12.dll
dbdsn.exe
dbelevate12.exe
dbeng12.exe
dbeng12.lic
dbicu12.dll
dbicudt12.dll
dblgen12.dll
dbserv12.dll
sqlany.cvf
Note: If you want to distribute the 64-bit database server, the above files will be located in the
Bin64 folder.
The sample database file (demo.db) is found at the location below. It will also need to be copied to the
above folder:
C:\Documents and Settings\All Users\Documents\SQL Anywhere 12\Samples
Open the SimpleViewer solution. Click Start -> All Programs -> SQL Anywhere 12 -> Sample
Applications and Projects -> SQLAnywhere -> ADO.NET -> SimpleViewer -> SimpleViewer.sln.
Note: Youll need to convert the project if you are using a newer version of Visual Studio. Allow
Visual Studio to do this automatically.
2.
3.
Add the database runtime files to the project (see Preparation step above for list of files). This
can be done by right-clicking the SimpleViewer project in the Solution Explorer and selecting
Add -> Existing Item... These files need to be added to the solution so that they are available to
the ClickOnce publishing options.
For all the newly added files, make sure that their build action property is set to Content and
their copy to output directory property is copy if newer. This is required so that these files
are included in the deployment without compiling or building them.
4.
We have added dsn.bat to the solution. Now we need to be sure the program runs it before the
application starts. We can do this by creating a method that will run dsn.bat before the
application starts. To do this, create a C# class by right clicking the SimpleViewer project and
selecting Add -> New Item... -> Class. Name this class PreDeploymentEvents.cs and click add.
5. In the newly created C# class called PreDeploymentEvents.cs, add the following namespaces:
using System.Diagnostics;
using System.Deployment.Application;
And add the following method inside the body of class PreDeploymentEvents:
6.
Now we need to make sure to call the RunBatch function before the program starts so that the
ODBC data source is defined before we run the application. Do this by opening Program.cs and
adding the following line of code after the static void Main() function:
PreDeploymentEvents.RunBatch();
You can now build the project by selecting Build Solution from the Build menu. You may need to change
the target framework of the project to be .NET Framework 3.5 (see next section on how to do this).
The solution should build without any errors.
2.
On the left column click on Application. Make sure the target Framework is set to .NET
Framework 3.5. If prompted to change the framework, accept it. Click the Publish tab on the
left.
3.
4.
5.
10
Click on Prerequisites.... This is used to select the programs the end-user will need to have
before running the application. Select .NET Framework 3.5 SP1 and press OK
Click on Application Files and make sure that for all the files being included, the Publish
Status is set to Include, the Download Group is set to (Required) and make sure the Hash
property is set to Include. Click OK.
Set the location of the Publishing folder location. In this demonstration, it will be located at C:\SimpleViewer\. This is where the application files will be stored after the application is
published.
6.
Click on Updates.. and make sure that The application should check for updates is NOT
checked so that the application is not self-updating. Later, we will be going over how to update
the application.
7.
Click on Options... and then open the Deployment tab on the left. Make sure that Use
.deploy file extension is NOT checked so that the files deployed do not have a .deploy
extension in them.
11
8.
9.
Application Files
Publish.htm
setup.exe
SimpleViewer.application
The next step is to run the application. We recommend that you transfer the contents of the folder
C:\SimpleViewer to another computer or virtual machine image that does not have SQL Anywhere
installed. This will more accurately simulate a typical deployment environment.
Run setup.exe to install the application (you can safely ignore the publisher warning).
12
10. The application should now be running with a Windows based form. You can then close the
application.
13
11. Right-Click on the SQL Anywhere icon in the system track (lightning bolt) and click Restore
from the popup menu. Take note of the current version number at the top.
The application can now be removed using Add or Remove Programs in Control Panel
14
Note that the uninstall will NOT remove the ODBC data source name created when the application
first ran. To remove this DSN, open a Command Prompt and change to the directory
C:\SimpleViewer\Application Files\SimpleViewer_1_0_0_1 and execute the following:
dbdsn.exe du SQL Anywhere 12 Demo y
Go ahead and completely remove the SimpleViewer application.
15
Open the SimpleViewer project, right-click SimpleViewer in the Solution Explorer and select
Properties.
Open the Publish tab
Set the Publishing Folder Location to http://<Your-Host-Name>/SimpleViewer (default is
http://localhost/SimpleViewer)
Note: If you do not want to publish using a web browser, you can leave the publishing folder
location to C:\SimpleViewer. However, every time you update the application, you will need to
copy the necessary installation files to your deployment computer or virtual machine image.
4.
16
Click on Updates... select The application should check for updates and Before the
application starts and press OK.
5.
6.
17
7.
8.
Close the application. Back in your development machine, close Visual Studio and copy the
SimpleViewer folder to a safe location. It is good practice to keep a backup of the project in case
anything goes wrong during the update.
We will now be applying an Express Bug Fix (EBF). EBFs are fixes to reported software defects
and are released periodically. To find EBFs for SQL Anywhere, navigate to
http://downloads.sybase.com/swd/summary.do?baseprod=144&client=ianywhere.
Register for a free MySybase account if you havent done so already. Click on SQL Anywhere and
scroll down to Platform:Windows x86/Windows x64. Select the newest SQL Anywhere Express Bug
Fix. Agree to the terms and conditions and click continue.
..
9.
10. Run the EBF executable. When the setup wizard appears, click Update and then click Finish.
The EBF will modify a few files in your current SQL Anywhere installation. The files that were
updated will have an updated version stamp.
18
The
11. Reassemble the updated database runtime files required into a new folder. These will have
newer version numbers.
12. Launch Visual Studio, open the SimpleViewer project and delete all the old runtime files that
were added earlier, excluding demo.db, dsn.bat and PreDeploymentEvents.cs.
13. In the Solution Explorer, open References and delete iAnywhere.Data.SQLAnywhere.v3.5. The
EBF above updated the SQL Anywhere ADO.NET data provider, so we need to re-compile the
project with the updated version.
14. Add the updated iAnywhere.Data.SQLAnywhere.v3.5 by right-clicking References and selecting
Add Reference... -> Browse to the location of the new iAnywhere.Data.SQLAnywhere.v3.5 . The
default location is C:\Program Files\SQL Anywhere 12\Assembly\V3.5.
15. Add the new database runtime files and be sure that for these files, the Build Action is set to
Content and their Copy to Output Directory to Copy if newer.
19
16. Open the project properties and go to the Publish tab. Click on Application Files and make sure
iAnywhere.Data.SQLAnywhere.v3.5.dll has its Publish Status set to Include, Download Group
set to (Required) and Hash set to Include.
17. Publish the application by right-clicking the project and selecting Publish... and Finish.
18. Now in your deployment computer, open the SimpleViewer application from the start menu.
19. A prompt will open up asking if you want to update the application. Click OK.
20. Right-click on the SQL Anywhere icon in the system tray and click Restore. You will see that
the database engine has been updated to the newest version.
20
21
Conclusion
This tutorial showed you how to generate a ClickOnce deployment package to distribute a SQL
Anywhere-powered .NET database application. SQL Anywheres integration with leading development
environments, such as Visual Studio, allows developers to quickly implement world-class solutions and
bring them to market as fast as possible.
For more information about SQL Anywhere and .NET technologies, please visit the SQL Anywhere .NET
Developer Center: http://www.sybase.com/developer/library/sql-anywhere-techcorner/microsoft-net.
22
SYBASE, INC.
WORLDWIDE HEADQUARTERS
ONE SYBASE DRIVE
DUBLIN, CA 94568-7902 USA
Tel: 1 800 8 SYBASE
www.sybase.com
Copyright 2011 Sybase, an SAP company. All rights reserved. Unpublished rights reserved under U.S.
copyright laws. Sybase, [and] the Sybase logo, [and] [LIST SYBASE TRADEMARKS] are trademarks of Sybase, Inc.
or its subsidiaries. indicates registration in the United States of America. SAP, [and] the SAP logo, [and] [LIST
SAP TRADEMARKS] are the trademark(s) or registered trademark(s) of SAP AG in Germany and in several other
Deploying a SQL Anywhere .NET Application Using ClickOnce
countries. All other trademarks are the property of their respective owners. MM/YY L0xxxx
23