VISUAL BASIC (VB) 3.0 IS A POPULAR TOOL for developing both stand-alone and client/server applications. A major reason for this popularity is that it enables Rapid Application Development (RAD). VB 3.0 lets corporate developers quickly prototype and build Windows applications. As a result, although VB 3.0 is a single-user development tool, it has moved to the forefront of client/server application development tools. For corporate developers, coupling VB's integrated Data Control and visual design environment with SQL Server's high-performance SQL database provided a robust environment for corporate client/server application development.
However, specialized client/server development environments such as Powerbuilder have exposed some weaknesses in VB 3.0. While VB 3.0's Data Control allowed very easy stand-alone program development, VB 3.0 was not as good for client/server development. The Data Control and VB 3.0's built-in database access objects (DAOs) were built for local databases, not Open Database Connectivity-enabled (ODBC) databases. VB 3.0's DAO is based on the Joint Engine Technology (JET) originally built for Microsoft Access. JET's local query processor resulted in inefficient ODBC calls and slow server data access compared to more efficient specialized client/server tools such as Powerbuilder.
Furthermore, VB 3.0 has no team application-building facilities: It is targeted at the single developer. Coordinating the work of multiple developers is no easy task in VB 3.0; for multiple developers to concurrently work on the same project, manual conventions or third-party tools are necessary. On top of all this, VB 3.0 can build only 16-bit applications--it cannot develop native 32-bit applications for Windows 95 or Windows NT.
Microsoft addressed these problems in the 4.0 release of Visual Basic, a 16- and 32-bit development environment that builds on the successful foundation of VB 3.0. For starters, VB 4.0 introduced a new version called the Enterprise Edition. Aimed clearly at the corporate client/server developer, the VB 4.0 Enterprise Edition takes up where the VB Professional Edition leaves off. The most important client/server feature in the new Enterprise Edition is a high-performance RemoteData Control. Unlike VB 3.0's Data Control, which is based on the JET engine, the new RemoteData Control provides a thin wrapper over ODBC. The ODBC orientation lets the RemoteData Control perform better when you're accessing ODBC databases such as SQL Server.
Microsoft also boosted VB 4.0's client/server development capabilities by adding the ability to create Object Linking and Embedding (OLE) servers. OLE servers let you create three-tiered client/server applications: The business rules are encapsulated in an OLE server program that is separate from both the client application (which typically contains the user interface) and the database server (which contains the data tables an application uses). You can see the evolution of VB in table 1.
VB 4.0 Enterprise Edition also provides team application-building capabilities through the integration of Microsoft's Visual SourceSafe. You call Visual SourceSafe directly from VB 4.0's menu, and Visual SourceSafe supports source control through check-in and check-out functions and project version control and history. For more information about using SourceSafe with VB 4.0, refer to the sidebar, "Team Development with VB 4.0 Enterprise Edition," on page 78.
VB 4.0 includes several client/server database access alternatives. Let's quickly look at the options to understand the differences among them and see where each option works best.
- The Data Control: VB's Data Control and DAO use the Microsoft JET Engine and were originally intended to support the Access database. The Data Control and the other VB bound controls make program development very easy, but they also introduce undesirable overhead for accessing remote data sources such as SQL Server. This situation makes the Data Control and the DAO best suited for applications that need to access data only on the local system.
- The Visual Basic Library for SQL Server: The Visual Basic Library for SQL Server (VBSQL) provides a high-performance method for accessing SQL Server databases. VBSQL does not support bound controls, so application coding is required for database access. Although VBSQL provides complete access to the capabilities of SQL Server, this SQL Server-only focus is a double-edged sword that also limits VBSQL to use only with SQL Server. Likewise, all the major database vendors (e.g., Oracle, Sybase, IBM, Borland) provide similar libraries for accessing their respective databases. All these options provide good client/server performance, but they also lock you into one vendor's database.
- The ODBC Application Programming Interface: Coding directly to the ODBC application programming interface (API) provides high-performance remote database access and portability to multiple database platforms, but this approach does not support bound controls. The ODBC API is a collection of 56 functions, and implementing it in your applications requires substantial coding and a good understanding of this API. It's like the inverse of the VBSQL library because the API's standardized database support lets it work with many different databases, but it doesn't support any vendor-specific implementation features that are unique to a particular database. Although you can use ODBC for local database access, it's really best suited for accessing remote SQL databases such as SQL Server, Oracle, and DB/2.
- The RemoteData Control: As you can see, each of these methods has its purpose, but each also leaves something to be desired. VB 4.0's RemoteData Control and Remote Data Objects (RDO) attempt to provide the best of both worlds: easy program development and high-performance data access. The RemoteData Control combined with the other VB bound controls makes no-code client/server database access easy and provides good client/server performance. Because the RemoteData Control is based on ODBC, it's also suitable for multiple-platform database access. This potent combination is likely to make the RemoteData Control and RDO your first choice for client/server database application development.
Screen 1 presents the VB 4.0 development environment. You can see the new RemoteData Control and the other data-aware custom controls that are a part of the VB 4.0 Enterprise Edition. The appearance of the RemoteData Control is similar to the Data Control. Both the icon in VB's toolbox and the control that appears on the form look just like the old Data Control. However, the RemoteData Control is new and is implemented with the 32-bit MSRDC32.OCX found only in the VB 4.0 Enterprise Edition.
The differences between the RemoteData Control and the old Data Control become apparent when you look closely at the properties of the RemoteData Control. Not surprisingly, the RemoteData Control properties are closely modeled after the parameters that the ODBC API uses. For instance, in screen 1, you can see the properties of LockType, LoginTimeout, Password, ReadOnly, ResultsetType, RowsetSize and SQL. All these values are manifestations of various ODBC API function parameters, and this close relationship with ODBC lets the RemoteData Control provide good client/server performance.
|TABLE 1: The three Visual Basic 4.0 Editions.|
|Visual Basic Standard Edition||$99||32-bit Applications Only
32-bit Data Control and DAO
Local Database Support
(Access, Paradox, dBASE, Btreive)
|Visual Basic Professional Edition||$499||All the features of VB Standard Edition
32-bit and 16-bit Applications
20+ Additional Custom Controls
ODBC Database Support
SQL Server and ORACLE ODBC Drivers
Integrated Data Manager
OLE Server and Component Creation
|Visual Basic Enterprise Edition||$999||All the features of VB Professional Edition
32-bit RemoteData Control and RDO
Integrated Version Control (Visual SourceSafe)
Remote OLE Automation
Put to Work
With a basic understanding of VB 4.0's new RemoteData Control under our belts, let's put that knowledge to work by using this facility to connect to an SQL Server database. First, to use the RemoteData, you click on its icon in VB's toolbox and then drag-and-drop it onto your VB form. After you add the control to your form, you must set its connection properties by clicking with the right mouse button on the RemoteData Control. The RemoteData Control connection properties window you see in screen 2 will be displayed.
The Data Source text box lets you enter the data source name you want to connect to. The example in screen 2 shows how to connect to a data source named TECADB, which is a SQL Server database in this example. You can manually enter the name of the data source, or you can click on the drop-down box, and a list of all available data sources will be displayed. One important point is that before you can use the RemoteData Control to connect to a data source, you must define that data source by means of the ODBC Administration program.
The next set of prompts lets you enter the user name and password for accessing the SQL Server database. Finally, you enter the SQL statement in the SQL text box. This is the SQL statement that will be sent to the SQL Server database. This statement identifies the database tables to use and the rows and columns to select. You can enter any valid SQL statement. The simple SQL statement select*fromaccount in screen 2 selects all the rows and all the columns from the table named "account."
Note that this simple example is for illustration purposes only. As a general rule, you won't code such inclusive SQL statements. Consider what happens if you run this statement against a table containing a million rows. Your application will attempt to retrieve the entire million rows. Instead, you limit the amount of data that your application deals with by coding a more restrictive SQL statement, such as
select number, description, amount from account where amount > 50000
After setting the connection properties of the RemoteData Control, you need to add a bound control to your VB form. To add the new DBGrid Control, you simply select the DBGrid Control from the VB toolbox and drag-and-drop it onto your form. After you add the control to your form, you must set its Data Mode and Data Source properties. This example uses a Data Mode property of 0 - bound, which sets up this control as a bound control (a bound control is automatically linked to the Data Control or RemoteData Control named in the Data Source property). I set the Data Source property to the RemoteData Control named MSRDC1. If you want, you can also specifically set each column in the DBGrid Control to a column from the SQL table, using the Columns property form in the DBGrid's Custom dialog. If you leave this property blank as in this example, the grid will automatically create a column for each SQL database column that the SQL statement returns. Running the new application results in the window shown in screen 3.
The resulting application is a native 32-bit Windows program that can run on either Windows 95 or Windows NT. When the application starts, you receive a prompt to log in to the SQL Server database. Then the SQL statement you entered into the RemoteData Control is executed, and the data is returned from the SQL server database and displayed in the grid. If you set the AllowUpdate properties of Grid to True, you can edit the data presented in the grid.
That's all the programming you need to begin writing high-performance ODBC-based client/server applications with VB 4.0's new RemoteData Control. In addition to the RemoteData Control, VB 4.0 has Remote Data Objects (RDO), which provide a finer level of control over ODBC database connections.
Layer of Performance
VB 4.0's RemoteData Control brings both RAD and high-performance ODBC database access to your 32-bit application development environment. The RemoteData Control's thin layer over ODBC ensures good performance when you access remote databases such as SQL Server, and its easy, no-code programming allows quick application development. For client/server application development, the RemoteData Control and RDO make the VB 4.0 Enterprise Edition worth considering. The RemoteData Control and the other client/server enhancements to the VB 4.0 Enterprise Edition make it a strong competitor to any specialized client/server development platform.