`Book2
`
`Microsoft@ Visual Basic™
`
`Programming System for Windows™
`Version 3.0
`
`Professional Editon
`
`This volume contains two separate books:
`Data Access Guide
`for Visual Basic User's Manual
`
`Crystal Reports
`
`Microsoft Corporation
`
`Microsoft Corp. Exhibit 1104 Page 1409
`
`
`
`Information in this document is subject to change without notice. Companies, names, and data used in
`examples herein are fictitious unless otherwise noted. No par of this document maybe reproduced or
`transmitted in any form or by any means, electronic or mechancal, for any purpose, without the
`express written permission of Microsoft Corporation.
`
`@1993 Microsoft Corporation. All rights reserved.
`
`Microsoft and MS-DOS are registered trademarks, and Windows and Visual Basic are trademarks of
`Microsoft Corporation in the USA and other countres.
`
`Btrieve, Xtrieve, NetWare, and Novell are registered trademarks of
`
`Novell, Inc.
`
`Crystal Reports is a trademark of Crystal Computer Services Inc.
`dBASE II and dBASE IV are registered trademarks of Borland International, Inc.
`Oracle is a registered trademark of Oracle Corporation.
`Paradox is a registered trademark of Ansa Software, a Borland company.
`SYBASE is a registered trademark of Sybase, Inc.
`
`Document Number DB52324-0793
`Printed in the United States of America.
`
`/ ,
`tš .
`
`Microsoft Corp. Exhibit 1104 Page 1410
`
`
`
`CHAPTER 1
`Introduction to Data Access
`with Visual Basic
`
`1
`
`Virtually all applications written today are used to gather information and store it
`for later retrievaL. More and more, this data is managed using the formal structure
`of a database. The Microsoft@ Visual Basic™ programmng system for the
`Windows™ operating system now enables you to create databases and to build
`applications that serve as front-ends to many of the popular database formats. By
`adding built-in data storage and retrieval routines, Visual Basic makes database
`management simple, fast, and trouble-free.
`
`Visual Basic implements data access by incorporating the same database engine
`that powers Microsoft Access@. Combined with Visual Basic, this technology
`gives you seamless access to many standard database formats, including
`Microsoft Access, Btrieve@, dBASE@, Microsoft FoxPro@, Oracle@, Paradox@,
`and Microsoft SQL Server. If you have an existing database created in one of
`these supported formats, you can use Visual Basic to manipulate it.
`
`By using data access objects such as the Database, Table, Field, and Index
`objects, Visual Basic enables you to manipulate databases with a minimum of
`programmng. The data object model simplifies the code you need to write and
`structure and mechanics of retrieving and
`updating data. You can use the same data access objects and the same properties,
`methods, and functions to work with all of the supported database formats.
`
`insulates you from the underlying
`
`The Visual Basic database access architecture is extensible, so you can use
`additional database drivers as they are developed. And with the flexibility of the
`database object model, you'll need to make few or no changes in your code to
`implement them.
`
`This version of Visual Basic no longer depends upon Open Database Connectivity
`(ODBC) as its sole means of database connectivity. ODBC access is stil a viable
`means of connecting to external databases from Visual Basic, however, and
`ODBC is stil used to connect to Microsoft SQL Server and Oracle database
`management systems.
`
`Microsoft Corp. Exhibit 1104 Page 1411
`
`
`
`2 Data Access Guide
`
`The Data Access Guide
`Although the primar focus of the Data Access Guide is on programming data
`access objects, it also highlights the features of the data control that are enhanced
`by the Professional Edition. Since the data control can significantly reduce the
`amount of code you need to write for an application, you'll find that its extra
`capabilties in the Professional Edition wil make your job easier and your
`applications more powerfuL.
`
`Contents
`The Data Access Guide is designed to help you use existing databases, create new
`ones, and build .applications to access them. The chapters in the Data Access
`Guide cover the following topics:
`
`Chapter 1, "Introduction to Data Access with Visual Basic," provides a quick
`overview of the Data Access Guide and lists summar tables of data access
`objects, properties, methods, and events.
`
`Chapter 2, "Database Management Using Visual Basic," discusses data definition
`language and shows how to open an existing database, create a new database, and
`manage the databases you work with.
`
`Chapter 3, "Creating Programs to Manipulate Data," discusses data manipulation
`language and shows how to use Visual Basic to extract and manipulate data from
`databases.
`
`Chapter 4, "Using Visual Basic Controls with Data Access Objects," presents
`information on using bound and unbound controls in the Professional Edition.
`
`Appendix A, "Using Microsoft Access Databases," discusses the unique aspects
`of working with databases created and manipulated by Microsoft Access.
`
`Appendix B, "Microsoft Access SQL," provides a detailed description of the SQL
`language used to create SQL queries.
`
`Appendix C, "Accessing External Databases," discusses the details of accessing
`data in external databases and ODBC tables.
`
`Microsoft Corp. Exhibit 1104 Page 1412
`
`
`
`Chapter 1 Introduction to Data Access with Visual Basic 3
`
`Data Access Sources
`Visual Basic enables your applications to manipulate the data and underlying data
`structures of many types of database applications. For example, you can use
`Microsoft Access to create and manage a database that your Visual Basic
`programs can manipulate. In the same way, you can create databases in Visual
`Basic that Microsoft Access can manage. Visual Basic also provides access to
`several other popular database formats. There are three categories of databases
`that Visual Basic recognizes:
`
`· Microsoft Access-format databases. These database files are manipulated
`directly by Visual Basic and can be created or manipulated with Visual Basic
`or Microsoft Access. This is the Visual Basic native format-it provides the
`
`most flexibilty and speed.
`
`· External databases. This category includes database formats such as Btrieve,
`dBASE III@, dBASE IV@, Microsoft FoxPro versions 2.0 and 2.5, and
`Paradox. You can create or manipulate all of these database formats in Visual
`Basic. Be sure to consult online Help files to determne which external
`databases are currently supported. The ISAM files created with Visual Basic
`for MS-DOS@ are not supported directly, but these files can be exported to
`ASCII format and re-imported into Visual Basic using a Visual Basic program.
`· External ODBC databases. This category includes client/server databases such
`as the Microsoft SQL Server and Oracle database management systems. In the
`case of ODBC databases, you can pass SQL commands directly to the external
`server for processing.
`
`Alternatives to Visual Basic Data Objects
`Data objects are not the only means you have of manipulating data from Visual
`Basic. You also have access to the following sources:
`
`· Sequential, random, and binary file-access methods. Built-in statements such
`as Get, Input, Print, and Put allow you to directly manipulate these types of
`files.
`· Visual Basic SQL Librares (VBSQL) for Microsoft SQL Server. VBSQL
`provides a direct link to the C language applications programming interface
`(API) to DB-Librar functions. You can use this API to communicate directly
`with Microsoft (or SYBASE@) SQL Server.
`· ODBC Librares. It is also possible to develop applications that call the ODBC
`API directly. Although this method is more complex to implement, it provides
`a closer link between the application and the ODBC host than using data
`objects.
`
`Microsoft Corp. Exhibit 1104 Page 1413
`
`
`
`4 Data Access Guide
`
`· Third-pary dynamic-link librares (DLLs) and custom controls. A number of
`other software developers provide data-aware bound controls as well as data-
`access custom controls that you can make par of your Visual Basic
`application design.
`
`Unlike using Visual Basic data access objects, most of these alternatives require a
`thorough understanding of the fie structure, access methods, and server control
`methodologies. The benefit of these approaches is more detailed control over the
`fies or host server, often at the cost of database-independent code.
`
`Professional Edition Support
`Several Visual Basic data access features are active only when you use the
`Professional Edition. The following table compares the features provided in the
`Standard and Professional Editions.
`
`Table 1.1 Features in the Standard and Professional Editions
`
`Feature
`
`Standard Edition
`
`Professional Edition
`
`Bound controls
`Data control
`Create Database object
`Create Dynaset object
`Create Index object
`Create QueryDef object
`Create Snapshot object
`Create Table object
`. Create data access objects
`Create new databases
`Modify database structure
`
`Yes
`Yes
`Only with the data control
`Only with the data control
`No
`No
`No
`No
`No
`No
`No
`
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`Yes
`
`In the Standard Edition, access to data is provided only through the data control.
`
`Microsoft Corp. Exhibit 1104 Page 1414
`
`
`
`Chapter 1 Introduction to Data Access with Visual Basic 5
`
`Data Access Object Summary
`
`Table 1.2 Objects and Collections
`
`Objects or collections
`
`Properties
`
`Database object
`
`Dynaset, Table,
`Snapshot recordset
`objects
`
`CollatingOrder
`Connect
`Name
`QueryTimeout
`Transactions
`Updatable
`
`BOF
`Bookmark
`Bookmarkable
`DateCreated
`EOF
`Filter
`Index
`LastModified
`LastUpdated
`LockEdits
`Name
`NoMatch
`RecordCount
`Sort
`Transactions
`Updatable
`
`Methods
`
`BeginTrans
`Close
`CommitTrans
`CreateDynaset
`CreateQueryDef
`CreateSnapshot
`DeleteQueryDef
`Execute
`ExecuteSQL
`ListFields
`ListTables
`OpenQueryDef
`OpenTable
`Rollback
`
`AddNew
`Clone
`Close
`CreateDynaset
`CreateSnapshot
`Delete
`Edit
`FindFirst
`FindLast
`FindNext
`FindPrevious
`ListFields
`Listlndexes
`MoveFirst
`MoveLast
`MoveNext
`MovePrevious
`Seek
`Update
`
`Microsoft Corp. Exhibit 1104 Page 1415
`
`
`
`6
`
`Data Access Guide
`
`Table 1.2 Objects and Collections (continued)
`Properties
`
`Objects or collections
`
`Field object
`
`Index object
`
`TableDef object
`
`Attributes
`CollatingOrder
`Name
`OrdinalPosition
`Size
`SourceField
`SourceTable
`Type
`Value
`
`Fields
`Name
`Primar
`Unique
`
`Attrbutes
`Connect
`DateCreated
`LastUpdated
`Name
`SourceTableName
`Updatable
`
`QueryDef object
`
`TableDefs, Fields,
`Indexes collections
`
`Name
`SQL
`
`Count
`
`Methods
`
`Append
`
`Chunk
`
`FieldSize
`GetChunk
`
`(None)
`
`(None)
`
`Close
`CreateDynaset
`CreateSnapshot
`Execute
`ListParameters
`Append
`Delete
`Refresh
`
`Data access methods
`Refresh
`UpdateControls
`UpdateRecord
`
`Data access events
`
`Error
`Reposition
`Validate
`
`Table 1.3 Data Control
`
`Data access properties
`
`Connect
`Database
`DatabaseName
`EditMode
`Exclusive
`Options
`ReadOnly
`Recordset
`RecordSource
`
`Microsoft Corp. Exhibit 1104 Page 1416
`
`
`
`Chapter 1 Introduction to Data Access with Visual Basic 7
`
`Table 1.4 Bound Controls
`
`Data access properties
`
`Data access methods
`
`Data access events
`
`DataChanged
`DataField
`DataSource
`
`(None)
`
`(None)
`
`You can use the following Visual Basic statements and functions for data access:
`
`· BeginTrans statement
`· CommitTrans statement
`· CompactDatabase statement
`· CreateDatabase function (Professional Edition only)
`
`· FreeLocks statement
`· OpenDatabase function (Professional Edition only)
`
`· RegisterDatabase statement
`
`· RepairDatabase statement
`
`· Rollback statement
`
`· SetDataAccessOption statement
`
`· SetDefaultWorkspace statement
`
`Microsoft Corp. Exhibit 1104 Page 1417
`
`
`
`Microsoft Corp. Exhibit 1104 Page 1418
`
`Microsoft Corp. Exhibit 1104 Page 1418
`
`
`
`CHAPTER 2
`
`Database Management
`Using Visual Basic
`
`9
`
`This chapter focuses on the Data Definition Language (DDL) you can use to
`define database structures. It explains how you can use functions, statements,
`methods, properties, and data access objects to define your database tables, fields,
`and indexes. Included are discussions of techniques you can use to create new
`databases, modify database structures, and manage databases.
`
`There are four ways you can start this chapter:
`
`· If you have an existing database and want to lear how to open it, star with
`the section "Opening a Database."
`· If you want to create a new database from scratch, star with the section
`"Creating a Database."
`· If you want to modify an existing database, star with the section "Modifying
`the Structure of a Database."
`· If you want to perform maintenance on a database, star with the section
`"Managing a Database."
`
`You can use the sample database BIBLIO.MDB provided with Visual Basic to
`explore many of the topics in the Data Access Guide. You should also read
`Chapter 20, "Accessing Databases with the Data Control," in the Programmer's
`Guide for an overview of working with databases in Visual Basic.
`
`Contents
`· Opening a Database
`· Mapping the Structure of a Database
`
`· Creating a Database
`· Modifying the Structure of a Database
`
`· Managing a Database
`
`Microsoft Corp. Exhibit 1104 Page 1419
`
`
`
`10 Data Access Guide
`
`Opening a Database
`Begin with this section if you already have a database that you want to use with
`Visual Basic. You can use two different methods to open a database in Visual
`Basic:
`
`· Use the data control.
`· Use the OpenDatabase function.
`
`Using the Data Control
`Using the data control can significantly reduce the amount of code you need to
`open and manipulate a database. The data control imposes few limitations on the
`functionality, flexibility, or robustness of your applications, so you can use the
`data control in most situations.
`
`You connect the data control to a database by setting properties. Once the data
`control is set up, you can perform many core functions with little or no code:
`
`· Open the database and create an associated Database variable.
`· Create a Dynaset object containing the data.
`· Move the current record pointer within the resulting data records.
`· Use bound controls to accept and post changes to the database.
`· Provide an error handler.
`
`To learn more about opening a database using the data control, see Chapter 20,
`"Accessing Databases with the Data Control," in the Programmer's Guide.
`
`If you choose not to use the data control to open a database, you will not be able
`to use bound controls to display or edit your data, as each bound control must be
`control. There are also restrictions on using the data control
`with the OpenDatabase function. For more information, see "Using
`OpenDatabase with the Data Control," later in this chapter.
`
`assigned to a data
`
`Using the Open
`
`Database Function
`The other way to open a database is to use the OpenDatabase function to create a
`Database object. A Database object you create with the OpenDatabase function
`is identical to a Database object you create with the data control. The
`OpenDatabase function is designed to perform the following tasks:
`
`· Name the source of the data.
`
`· Describe your database access method.
`· Indicate single-user or multiuser mode for the database.
`
`Microsoft Corp. Exhibit 1104 Page 1420
`
`
`
`Chapter 2 Database Management Using Visual Basic 11
`
`. Indicate read-only or read/write access to the database.
`· Open the specified data source and create an associated Database varable.
`
`. Create a new database in the format of an external database, such as Btrieve,
`dBASE III, dBASE IV, Microsoft FoxPro, Oracle, Paradox, or SQL Server.
`
`The OpenDatabase function syntax is:
`
`OpenDatabase (databasename (, exclusive (, readonly (, connect))) )
`
`As the next example shows, you first use the Dim statement to create a Database
`variable, and then use the Set statement to assign that varable to the result of the
`OpenDatabase function.
`
`In the following example, the OpenDatabase function is used in its simplest form
`to open a shared, read/write, Microsoft Access-format database named
`BIBLIO.MDB, located in the current directory:
`
`Di m Db As Database
`Database ("BIBLIO.MDB")
`
`Set Db = Open
`
`Once you initialize the Database variable (in this caseD b), you can use it to
`examine or modify the BIBLIO.MDB database structure, or to access the database
`records.
`
`Using the Oatabasename and Connect Parts of
`OpenOatabase
`The databasename and connect pars of the OpenDatabase function work in
`tandem to identify the source and format of the data. The source of your database
`can be on your workstation, on a shared network server, or on an ODBC server.
`The database can be in the form of a single .MDB file, a directory of database,
`data, index, and support files, or a registered ODBC data source name.
`
`· Databasename provides Visual Basic with the named source for the data. The
`databasename syntax depends upon the type of database you are opening.
`· Connect provides Visual Basic with the type of database to be opened and the
`optional parameters that may be needed to gain access to the database. The
`connect string is not case-sensitive.
`
`Microsoft Corp. Exhibit 1104 Page 1421
`
`
`
`12 Data Access Guide
`
`The following table shows each supported database format, the databasename
`part of the function, and the connect part of the function that indicates the data
`source type and any needed parameters.
`
`Database format
`
`Microsoft Access
`Btrieve
`dBASE III
`dBASEIV
`FoxPro Version 2.0
`FoxPro Version 2.5
`ODBC (SQL Server,
`Oracle)
`
`Paradox
`
`Databasename
`
`drive :\pathYžle .MD B
`
`drive :\pathYžle.D DF
`drive:\path
`drive:\path
`drive:\path
`drive:\path
`Registered data source
`name (usually the server
`name)
`drive:\path
`
`Connect
`
`(none)
`"Btrieve"
`"dBASE III"
`"dBASEIV"
`"FoxPro 2.0"
`
`"FoxPro 2.5"
`
`"Odbc;Dsn=Server; Uid=
`U ser;Pwd=Password"
`
`"Paradox"
`
`Note For Visual Basic and Microsoft Access-format databases, the full database
`file name (including .MDB extension) is provided in the databasename part of the
`function; no connect par is required. If Visual Basic does not find the file you
`specify, your application wil trigger a trappable error, and a new database wil
`not be created.
`
`For external databases, the databasename specifies the full path of the database
`directory. In the case of Btrieve, the databasename is the path to the FILE.DDF
`file. If your network supports Universal Naming Convention (UNC) file names,
`you can use these to address your database.
`
`Using the Exclusive Part of Open
`
`Database
`If you want to share your database with other users, set the exclusive part of the
`function to False. If the database is already opened by another user, you wil not
`be able to open it with the exclusive par set to True. Once your database is
`opened in exclusive mode, no other users wil be able to open it until you close it.
`The exclusive part of the function defaults to False (shared mode).
`
`If you open a database in exclusive mode, your application can still open the
`database again. In other words, you can open a database as many times as you
`want, even if you have already opened the database in exclusive mode.
`
`Microsoft Corp. Exhibit 1104 Page 1422
`
`
`
`Chapter 2 Database Management Using Visual Basic 13
`
`Using the Readonly Part of OpenOatabase
`If you want to open a database as read-only, set the readonly par of the function
`to True. When a database is opened as read-only, Visual Basic does not have to
`spend as much time dealing with read/write issues, which gives you faster access
`to the data. The default setting is False, for read/write access.
`
`If your application opens the same database multiple times, Visual Basic wil
`ignore the readonly part of the function on subsequent openings of the same
`database file. In other words, if you open a database as read-only, each time you
`subsequently open the database, the read-only mode wil be set. After each of
`these opened databases has been closed, you can change the read-only state.
`
`Special Conditions when Using OpenOatabase
`When you use the OpenDatabase function and specify an external database,
`Visual Basic either finds the database and all companion files and opens it, or
`delegates this operation to an external database engine. If an external (non-
`ODBC) database you specify does not exist, Visual Basic attempts to create a
`database in the format indicated by the databasename and connect parts of the
`function.
`
`Note Special conditions may apply when you connect to a Microsoft Access
`database that uses login names and passwords, or to non-ODBC external
`databases. For information on connecting to Microsoft Access databases, see the
`section "Managing a Database" later in this chapter. For information on
`connecting to ODBC databases, see the section "Considerations when Using
`ODBC Databases" later in this chapter.
`
`Once Visual Basic locates and opens the database, the OpenDatabase function
`supplies a Database object varable and properties. Each database is uniquely
`identified by its own Database variable. An opened Database variable is required
`for all operations that involve data access, whether you are creating a new
`database or modifying the structure of an existing database. You can open up to
`256 databases simultaneously.
`
`You may not be able to open your database if:
`
`· The database is already opened by another user (not including your own
`application) in exclusive mode.
`· A specific database file cannot be found. (Remember to include the entire
`path.)
`· You do not have permission based on the database's or the network's security
`settings.
`
`Microsoft Corp. Exhibit 1104 Page 1423
`
`
`
`14 Data Access Guide
`
`Opening Different Types of Databases
`The following table illustrates the pars you might use with the OpenDatabase
`function to open several standard types of databases.
`
`Type of database
`
`Microsoft Access
`
`Btneve
`
`dBASE III
`
`FoxPro version 2.5
`
`ODBC (login dialog)
`Paradox
`
`A registered ODBC data
`source name ("Accounts")
`A defined ODBC DSN in
`ODBC.INI with additional
`connect string information
`
`OpenDatabase function and parts
`
`OpenDatabase( "MYOB. MOB". Fal se. Fal se. "")
`-Or-
`OpenDataba se ("MY DB. MOB")
`
`OpenOatabase("C: \MYBEE. DDF". Fal se. Fal se.
`.. "Btrieve;")
`OpenOatabase("C: \MYOBX". Fal se. Fal se.
`.. "dBASE III;")
`
`OpenDatabase("C:\MYFOX". False. False.
`~ "FoxPro 2.5;")
`OpenDatabase("". False. False. "ODBC;")
`
`OpenOatabase("C:\MYPDX". False. False.
`.. "Paradox;")
`
`OpenOatabase( "Accounts". Fal se. Fal se. "ODBC;")
`
`C$="ODBC; ui d=sa; pwd=zzx; DSN=Accounts;
`OpenDatabase("". False. False. C$)
`
`Using OpenDatabase with the Data Control
`You cannot use the OpenDatabase function to create a Database varable and
`supply it to the Database property of a data control. This is because the data
`control's Database and Recordset properties are read-only.
`
`Considerations when Using ODaC Databases
`The following paragraphs describe some of the unique conditions you should be
`aware of when working with ODBC databases. For more information on ODBC
`databases, see Appendix C, "Accessing External Databases."
`
`The Open
`
`Database Function and ODBC Data Sources
`If the information provided in the OpenDatabase function is insufficient for
`Visual Basic to open your database, the ODBC interface wil provide a login
`dialog box to gather the missing information (such as the user name, password,
`and default database).
`
`Microsoft Corp. Exhibit 1104 Page 1424
`
`
`
`Chapter 2 Database Management Using Visual Basic 15
`
`If you do not want the ODBC dialog box to appear, be sure to check the
`
`Connect
`property after the database is opened for the first time (during development). It
`wil have the values you provided in the ODBC dialog box. These values can be
`placed into the connect par of the function so the dialog need not appear again.
`
`Anytime that insufficient pars are provided in the connect string when opening an
`ODBC database, the ODBC dialog box is displayed. You can force the ODBC
`login dialog box to appear by using an empty string for databasename and setting
`connect to "00 Be; " or to "". You can also use this method to view all available
`ODBC data sources and available databases once you have provided a valid login
`name and password.
`
`In the case of ODBC data sources, the databasename part must correspond to a
`. registered entry in the ODBC.INI file, specifying a valid Data Source Name
`(DSN). The value supplied in the connect part of the function overrdes the value
`supplied by databasename.
`
`For More Information For more information on establishing valid data source
`names, search for RegisterDatabase in the online Help provided for ODBC-
`supported databases.
`
`Additional Connect Parameters
`For ODBC databases and other cases where you need to provide additional
`parameters for external databases, you may have to specify additional connect
`parameters to the OpenDatabase function. The syntax is:
`
`datasource type; (connect parameter; (connect parameter; ) )
`
`To set additional parameters, you first specify a valid data source type, follow it
`with a semicolon (;), and then indicate one or more of the following connect
`parameters. Make sure to separate each parameter with a semicolon.
`
`This connect parameter value
`
`Specifies
`
`UID
`PWD
`DSN
`
`DATABASE
`LOGINTIMEOUT
`
`APP
`WSID
`LANGUAGE
`
`User ID name.
`Password.
`Data source or server name. Can be
`specified in databasename.
`Default database to use on the server.
`Number of seconds to wait for the named
`server to respond to login request.
`Application name.
`Workstation ID.
`Default national language.
`
`Microsoft Corp. Exhibit 1104 Page 1425
`
`
`
`16 Data Access Guide
`
`For example, if the external database you are connecting to requires a password,
`you need to specify this password using the PWD parameter in the connect par of
`the function. The following code shows connect used to specify a Paradox
`database with a password of "mydbase":
`
`Set Db = OpenDatabaseCdatabasename("Paradox; PWD=mydbase;"J
`
`The OOBC QueryTimeout Property
`The QueryTimeout property determines the number of seconds that Visual Basic
`waits for an ODBC query or DDL operation to complete before triggering a
`trappable query time-out error. You can set this value for each database opened; it
`applies to all ODBC record sources created on the database. A value of zero
`specifies that no time-out wil occur.
`
`How the remote ODBC server wil react to your application timing-out depends
`on the server. In some cases the transaction in process wil be canceled and rolled
`back; in other cases the transaction may have already been partially or totally
`completed.
`
`For example, suppose you want to access two separate data sources,
`"LocaIServer" and "RemoteServer," on two fictitious ODBC servers. To set the
`QueryTimeout delay on each data source you would use the following code:
`
`Dim Dbl As Database
`Dim Db2 As Database
`Dim Ds As Dynaset
`Dim R As Integer
`Dim Con As String
`
`On Error GoTo MyTi meOutHandl er
`ConS = "ODBC;PWD=tgXpt44;Uid=Acnt;"
`Set Dbl = OpenDatabaseC"LocalServer". False. False. ConS)
`
`ConS = "ODBC; PWD=y5ttRw; Ui d=MgrAct;"
`Set Db2 = OpenDatabaseC"RemoteServer". False. False. ConS)
`Dbl.0ueryTimeout = 20 . Wait 20 seconds before time-out.
`Set Ds = Dbl.CreateDynasetC"Titles")
`
`Db2.0ueryTimeout = 120 ' Wait 2 minutes before time-out.
`R% = Db2. ExecuteSOi( "Update Authors Set Status=1 Where Status=6")
`
`Microsoft Corp. Exhibit 1104 Page 1426
`
`
`
`Chapter 2 Database Management Using Visual Basic 17
`
`The ODBC LoginTimeout Parameter
`To change the number of seconds that Visual Basic should wait for an ODBC
`server to respond to the open request before timing out, use the LoginTimeout
`parameter in the connect par of the function. For example, the following code
`sets the login time-out to 120 seconds:
`
`Di m Db As Database, C As Stri ng
`C$ = "ODBC; PWD=tgXpt44; Ui d=Acnt; Logi nli meout=120"
`
`On error Golo DBOpenError ' In case it ti mes out.
`Set Db = OpenDatabase("Dbtopics",False ,False, C$ )
`
`When opening ODBC database tables directly, or attaching tables from ODBC
`databases, you may find that the default time-out value set in the initialization
`fies is not sufficient for your needs. Since some servers may take several minutes
`to respond over slow networks, while others respond instantly, it is important to
`set the ODBC login time-out to an appropriate time limit for the specific situation.
`By setting appropriate times, you can make sure that users wil not be locked up
`unnecessarly or abandon a call to the OpenDatabase function that would have
`completed normally if left to run a few more seconds.
`
`When the login time-out limit is up, your application wil get a time-out error. In
`other cases Visual Basic informs you that the server you specified cannot be
`found. This may be because the server name you used is incorrect, the server is'
`down, the network link to it is down, or you do not have proper network
`permissions to access the server.
`
`Closing Database Objects
`Once you are done using a database, you should close it. Closing a database
`releases the resources that it holds, releases any locks or other shared resources
`that the database was holding, and rolls back any uncommitted transactions.
`
`If you used the OpenDatabase function to open your database, you must close all
`of the recordsets opened against it (the Tables, Dynasets, and Snapshots) before
`sets are closed, you can close the Database
`
`you close the database. Once all record
`
`with the Close method:
`
`Db.Close
`
`Explicitly closing Database variables is especially important if you use Global
`(module-level) or Static (local) Database varables. You do not need to explicitly
`close a database or recordset opened with the data control, as these databases are
`closed automatically when you unload the form upon which the data control
`resides. In addition, you do not need to explicitly close databases that are declared
`using local varables in a procedure, as all of the data objects are closed and the
`variables deleted when the procedure ends.
`
`Microsoft Corp. Exhibit 1104 Page 1427
`
`
`
`18 Data Access Guide
`
`Because Visual Basic doesn't free the memory used by data object varables until
`you explicitly clear the varables, end your program, restar your code, or close
`Visual Basic itself, any databases you refer to with these varables aren't
`automatically closed.
`
`When your program ends, the database is closed for you if you have not done so
`already. All incomplete transactions are rolled back (undone) and any incomplete
`edits are lost. You may want to intercept the QueryUnload event that occurs as
`your application is being closed. At this point you may be able to prompt the user
`for instructions on how to deal with incomplete edits or incomplete database
`operations.
`
`Mapping the Structure of a Database
`Once you have opened a database, you may want to expose or view the
`underlying strcture or schema to determine the Database object names and
`properties. This is called mapping the database. Once you have mapped your
`database, you'll find it much easier to write applications to manipulate the data.
`The following information on mapping database structures assumes that you
`understand how Visual Basic uses relational objects to reference database
`structure elements.
`
`Although you can use the data control to map database structures, using data
`access objects is easier and requires less code. To map your database, you need to
`do one of the following:
`
`· Use the Data
`
`Manager application.
`· Run a short Visual Basic procedure to map the database tables, fields, and
`indexes.
`· Use one of the List methods.
`
`When you map a database, you expose a number of properties that are fully
`discussed only in the Professional Edition. Information on many of these
`properties is presented within this section. For more information on these
`properties, search Help for the name of any specific property, or see the section
`"Creating a Database" later in this chapter.
`
`All examples in this section assume that you have opened the sample database
`using the following code:
`
`Dim i As Integer
`Dim Db As Database. Td As TableDefs
`Set Db = OpenDatabase("BIBLIO.MDB")
`Set Td = Db.TableDefs
`
`Microsoft Corp. Exhibit 1104 Page 1428
`
`
`
`Chapter 2 Database Management Using Visual Basic 19
`
`Mapping Database Object Properties
`Visual Basic sets the properties for the Database object when you open the
`database. Only the QueryTimeout property can be altered at run time. The
`following table summarzes the properties exposed by Database object.
`
`Property
`
`CollatingOrder
`Connect
`
`Name
`
`QueryTimeout
`Transactions
`Updatable
`
`Description
`
`The database collating order.
`The fully populated connect string used to open the
`database.
`The databasename par of the OpenDatabase function.
`Determnes the ODBC query time-out value.
`Indicates whether the database supports transactions.
`Indicates whether the database is updatable.
`
`You can use the following code to display the Database object's properties:
`
`Pri nt "Source of Data:", Db. Name
`Pri nt "Connect stri ng parameters:", Db. Connect
`Pri n