RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Building ASP.NET Applications with Delphi and Advantage Database Server

The Advantage Data Provider for .NET provides a feature-rich mechanism for Delphi developers using the Advantage Database Server (ADS) to build ASP.NET web applications and web services.


ike Delphi's other development platforms, Delphi for .NET offers a wide range of data access options for ASP.NET developers. These include support for the generic foundation class library (FCL) data access classes (ODBC and OleDb), dbExpress drivers, BDP for .NET providers, as well as support for all third-party solutions that support the ADO.NET data provider interface. (ADO.NET is the portion of the .NET FCL that applies to data access, storage, and manipulation.)

Fortunately, the choice of data provider for ASP.NET development is often uncomplicated. In most cases, you should use the data provider supplied by the publisher of the database. For Advantage, this is Advantage Data Provider for .NET, which from this point forward, I'll simply refer to as the Advantage Data Provider.

Because of the special capabilities of the Advantage Database Server itself, the Advantage Data Provider supports features unheard of in most other data providers. But there is a problem. You cannot begin a web page by dragging and dropping the Advantage Data Provider from Delphi's Data Explorer. Since Delphi's help tends to emphasize this approach, Advantage developers sometimes don't know where to begin.

Ideally, you should have a class, or set of classes—independent of the web pages on which their data is displayed—that perform data access.

Author's Note: You can find more detail on the reusable data layer approach here; however, while the paper demonstrates an abstract data layer, it does so in a very generic way. So generic, in fact, that the SQL statements in the example were embedded in the individual web pages. In practice, an abstract data layer encapsulates the queries, stored procedure calls, and views that embody the data access logic. Individual web pages often pass parameters to the exposed methods of the abstract data layer, and these affect the results that are returned, as opposed to passing entire query strings, which in part, defeats the de-coupling that an abstract data layer can provide.)

While the code you'll see here is amenable to the reusable data layer approach, this article, rather than focusing on the reusable data layer approach, sheds light on some of the components of the Advantage Data Provider that you use to access your Advantage data. For brevity, the discussion focuses only on the primary subset of components and techniques. However, that should be enough to get you started.

Author's Note: For more detailed information on using classes of the Advantage Data Provider, please refer to the Advantage help files. You may also want to reference Delphi's help and other .NET resources for more detailed explanations of the use of these and other classes available in ADO.NET.

Getting Started

Before discussing the principle classes of the Advantage Data Provider, you need to prepare your Delphi ASP.NET application to use Advantage. While the steps are not complex, they are essential.

You must begin with a Delphi for .NET ASP.NET application. The following steps assume you are using CodeGear's RAD Studio 2007; however, the steps are similar for both Borland Developer Studio (BDS) 2006 and 2005. The data layer abstraction technique described applies to ASP.NET applications written in Delphi Prism as well.

Start Delphi in a mode that includes the .NET personality. If you have installed the full version of RAD Studio, you can simply load RAD Studio, which includes all personalities. Alternatively, you can select the Window's Start Menu, select the CodeGear folder, and select either RAD Studio or Delphi for .NET. Delphi for .NET includes only the .NET personality.

Figure 1. New ASP.NET Web Application: The name you enter here serves as both the project source file name and the name of the ASP.NET virtual directory.
Author's Note: Because it's possible to install RAD Studio with some, but not all three of RAD Studio's personalities, if you did not install the Delphi for .NET personality, you need to re-install Delphi, this time ensuring that you select the .NET personality for installation.

With Delphi running, select File New ASP.NET Web Application from Delphi's main menu.

When the New ASP.NET Web Application dialog box appears (see Figure 1), enter the name of your application. This will be the name used for both your project source file and to create a virtual directory in the folder c:\inetpub\wwwwroot. For this example, enter the name AdsASPNETApplication. Click OK to continue.

You now have a new ASP.NET application, and can begin entering content and web controls. However, before you can begin accessing Advantage, you have to add the Advantage Data Provider assembly to the project's References folder. To do this, right-click on the References folder in the Project Manager, and select Add Reference (see Figure 2).

Figure 2. Adding a Reference: You need to add the Advantage Data Provider assembly to the project's references folder before you can access Advantage data.

Delphi displays the Add Reference dialog box (this requires a few moments to populate). You do not have to wait for the .NET Assemblies tab to be populated. Simply click the Browse button and navigate to the directory where the Advantage Data Provider is installed. The default location is c:\Program Files\Advantage\ado.net\2.0 (or 1.0 if you are using BDS 2006 or BDS 2005, because they use ASP.NET 1.1).

From this folder, select the Advantage.Data.Provider.dll and click Open. After you select an assembly, it appears in the lower portion of the Add References dialog box, as shown in Figure 3.

Figure 3. Selecting References: After you select an assembly, it appears in the New References list.
Figure 4. Populated References: Here's how the References folder should look after selecting the Advantage Data Provider DLL.

When you are done, click OK. Your References folder should now look something like Figure 4.

This next step is optional. My personal preference is to use the Advantage Data Provider assembly as a local copy, which means that Delphi will place a copy of the assembly in the bin subdirectory for your application. This lets you deploy the ASP.NET application to your web server by copying only the application directory structure without having to install any other files (other than the .NET framework itself, of course).

There are simply too many issues associated with this topic to cover here, so I will let you make your own mind up about this step. However, to follow my advice, right-click the Advantage.Data.Provider.dll assembly node in the References folder of Delphi's Project Manager and select "Copy Local" from the menu. Delphi will display a warning, but that's OK. Select "Yes" to accept the local copy designation.

Before you're ready to go you must also add the Advantage.Data.Provider namespace to the uses clause of any code unit from which you want to reference any Advantage Data Provider classes. Figure 5 shows an example of a uses clause where this namespace appears.

Figure 5. Using Namespaces: Add a "uses" clause to each code unit to reference Advantage Data Provider classes.

You are now ready to reference and use the classes of the Advantage Data Provider.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date