PROJECT FILE ARCHITECTURE

Before you create a new Project, you need to understand a few basics:

  • The new OLE DB technology

  • The new data link feature

  • The new Microsoft Data Engine

  • The primary objects available in a server database

Introducing OLE DB

OLE DB is a new set of data access utilities that expose data and database structures to your applications. In the past, you've used ODBC to link an Access application to non-Jet data. Although ODBC is still part of the Microsoft Office architecture, the new OLE DB components will be more important than ODBC to your present and future development efforts.

With OLE DB, Microsoft has defined a standardized architecture that provides a connectivity layer to various data types. OLE DB provides access to relational data like that in Jet and SQL Server databases. It also supports access to Microsoft Exchange data, flat files, spreadsheet data, and non-Microsoft server products.

Within OLE DB, there are three important terms to know:

  • Data source— The storage location for the data records, such as a table, file, message, or document.

  • Data consumer— The application that accesses data in the data source, such as an Access Project or C++ application.

  • Provider— The OLE DB engine (essentially, a small program) that allows the data consumer to connect to the data source, such as the OLE DB Provider for SQL Server used by an Access Project.

In Access 2000, you don't need to know how to programmatically communicate with an OLE DB provider; instead, you use a Data Link object to provide data to your application. Of course, you can also write VBA code to retrieve and manipulate data—when you do this with ADO, you are using OLE DB via ADO.

Linking to Data

When you create an Access Project, the Project uses an OLE DB data link to bind data and objects in a SQL Server database to the Project. The OLE DB provider that you use to create a data link between an Access application and SQL Server 6.5 or 7.0 is installed with Access 2000.

You can also use OLE DB providers to work with data from VBA program code by using ADO as discussed in Chapter 6, “Introducing ActiveX Data Objects.”

Note

Several OLE DB providers are installed by Access setup. To see the list of providers on your system, view the property sheet for a new or existing data link, as described in the following topic and shown later in Figure 26.2. For the purposes of this chapter and SQL Server development in general, the provider you will use is called the Microsoft OLE DB Provider for SQL Server.


Data Links and Access Projects

The data link between an Access Project and its SQL Server database is managed from the user interface. A new Connection option, added to the File menu in an Access Project, displays the Data Link Properties dialog box. It is here that you define a data link to the SQL Server data for your application (see Figure 25.1). An Access Project can use only SQL Server for the data and objects displayed in its Database window.

Figure 25.1. A Jet-based Access application doesn't show the File menu's Connection option.


Access 2000 .mdb files are still built on the Jet database engine and the Data Access Objects (DAO) technology, which uses the Microsoft Jet OLE DB Provider.

In a Jet-based application, each table in the application may be local to the application database or linked from another database. The Data Link Properties dialog in an Access Project enables you to identify the SQL server that will provide the application with data and database objects.

As a result, there's no central way to manage all the links between the application and its data. In contrast, an Access Project binds to a single server database through a single connection—a data link. Thus, you can change the entire database for a Project through the Data Link Properties dialog.

Note

The capability to change the entire database for a Project with a single data link change makes application development and enhancement easier. You can develop an application while connected to a test database and then easily change the Project's data link to the live server to place it in production.


Data Links and VBA Code

You can also use the new OLE DB data links by creating a data link disk file and using it from application code. Data link files, with a .udl file extension, can be used from an Access Project and a Jet-based application to define connection information for any OLE DB provider.

To create a data link file, follow these steps:

1.
In Windows Explorer, right-click and select New, then Microsoft Data Link.

2.
Name the new data link file.

3.
Right-click the link file and choose Properties.

4.
In the New Data Link Properties dialog, click the Provider tab. A list of available providers is displayed (see Figure 25.2).

Figure 25.2. These OLE DB providers are installed with Access 2000.


5.
Select a provider and click Next.

6.
On the Connection page, complete the required information. The type of information that must be entered varies based on the provider selected for the data link. For example, if the Microsoft OLE DB Provider for SQL Server is selected, a server name, database name, user name, and password must be entered on the Connection page (see Figure 25.3). On the other hand, if the Microsoft Jet 4.0 OLE DB Provider is chosen, a database file (.mdb) path and name must be entered (see Figure 25.4).

Figure 25.3. Specify these database properties for a data link that uses SQL Server.


Figure 25.4. Specify a database filename for a data link that uses Jet.


7.
Always click the Test Connection button to determine whether the data link information you entered provides for a successful connection to data.

The value of encapsulating connection information in a data link file is similar to the value received from ODBC data sources. If you've worked with ODBC before, you know that you can use a data source to connect application code to a certain set of data, and later change the data source to point to different data without changing any code. Similarly, a data link file can simplify your development and coding efforts.

Assume that several remote warehouses each create a daily receiving information file as an Access .mdb and send it in email to corporate headquarters. Sally, the inventory control manager at headquarters, has an Access Project that validates the warehouse files and loads the data into a SQL server. The Access code to do this in the Project looks something like this:

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset

cnn.Open "File Name=C:WhseLoad.Udl"
rst.Open "Receipts", cnn, , , adCmdTable
' ...
' In a Do loop, each record is validated and added to a server table here
' ...

rst.Close
cnn.Close

Notice that no Access database is specified. Instead, a data link file is named to provide connection information to the code. The data link file Load.Udl was created to use the Jet 4.0 OLE DB provider, which works with Access database files. In the data link file, a database name is specified, but this can easily be changed from Explorer without changing any code or properties inside the Access application that contains the code. Each time the code runs, it looks in the data link file for connection information. Therefore, when Sally gets a file from a remote warehouse, she simply does this:

1.
Opens the property sheet for the Load.Udl data link file and clicks the Connection tab

2.
Changes the database name to match that of the most recently received file

3.
Clicks a button in the Access application to run the preceding code

4.
Extracts the next warehouse file from email and repeats this process

Notice from Sally's workflow that she can use the same chunk of code to talk to several different .mdb files in several different locations without changing any code; she changes only the connection information in the data link file. This approach to coding gives you significant flexibility when writing code to work with data that is not accessed via the default connection for a Project.

Caution

This illustration is intended to show one way that a data link file can be employed, not to provide the best example of a workflow for Sally's business need. If you code your application to depend on a key .udl file such as the one in this example, be sure that you include code to test for improper manipulation or deletion of the data link file.


The Microsoft Data Engine

Much of your Access Project development can be done rapidly and portably, thanks to a new version of SQL Server that runs on your workstation. This version is the Microsoft Data Engine, or MSDE for short.

MSDE is a scaled-down version (but only barely so) of SQL Server 7.0, designed to run on a workstation. MSDE can be installed on Windows 9x and Windows NT workstations. Because MSDE is based on the same data engine as SQL Server, most Microsoft Access Projects or client/server applications run on either version unchanged.

Here are the limitations of MSDE as compared to a Windows NT Server–based SQL Server:

  • A 2GB database size limit

  • Supports Symmetrical Multiprocessing (SMP) for only two CPUs (only one CPU supported on Windows 9x)

  • Different memory management model (MSDE attempts to minimize memory usage, which may reduce performance)

  • Can't be a transaction replication publisher (but can be a subscriber)

  • Doesn't support a few high-end features such as parallel queries and fail-over clustering

Tip

If you need to do workstation development against very large SQL Server databases, you can upgrade the MSDE to the Desktop Edition of SQL Server 7.0. Simply install MSDE on your workstation from the Office CD set and then run setup for the Desktop Edition from the SQL Server CD set. SQL Server setup detects the MSDE and asks whether you want to upgrade. After the upgrade, your local Access Projects function the same, but the 2GB database size limit is gone.

Another advantage to installing SQL Server Desktop Edition, if you own it, is that Enterprise Manager is installed on your workstation, providing a broader toolset for managing SQL Server than is found in an Access Project.


MSDE isn't installed as part of Access 2000 setup. You install it from the CD file SQLX86SetupSetupSQL.Exe after you complete Access/Office setup. On a Windows NT workstation, MSDE runs as a service and starts automatically when you log on. On a Windows 9x workstation, the SQL Server engine and Service Manager are started with shortcuts in the Startup program group. You should see a small server icon for the Service Manager on the Windows taskbar, which can open this icon to start SQL Server if it's not running after you complete setup. If you want SQL Server to start up when you log on, make sure that you select the Auto-Start Service When OS Starts option at the bottom of the dialog. Figure 25.5 shows the Service Manager dialog.

Figure 25.5. The SQL Server Service Manager.


Objects on a SQL Server

At times, you can use an Access Project to connect to an existing SQL Server to create forms, reports, or code against the data. In other cases, you might need to create or enhance a SQL Server database from the Access Project. Figure 25.6 show the Database window in an Access Project; note that the list of objects you can work with varies from the list in a Jet-based application.

Figure 25.6. The Database window for an Access Project.


From an Access Project, you can work with the following SQL Server objects and tasks:

  • Tables— SQL Server tables are much like Jet tables in that they have fields, properties, and relationships to other tables. You work with table designs and data directly from a Project's Database window.

  • Views— A SQL Server view is what Access calls a query, but of a very limited variety. A SQL Server view joins tables and optionally applies criteria to the result set—it does not allow for actions (append, create table, delete, or update), does not sort the results, and does not support passed parameters. You work with view designs and data directly from a Project's Database window.

  • Database Diagrams— A SQL Server database diagram is more than a visual representation of a database's structure—you can create and modify tables, columns, and their attributes by working with the diagram. You work with diagrams directly from a Project's Database window.

  • Stored procedures— These scripts contain program code and database instructions. Think of a stored procedure as compiled code that runs as fast as possible because it's stored in the database with the objects it affects and not in your application. You work with stored procedures directly from a Project's Database window.

  • Triggers— A trigger is a stored procedure attached to a table-level event and defined to run automatically when a record in its table is modified. Triggers can be defined to run when table data is deleted, inserted, or updated, and are used to apply validation rules or maintain data integrity. Triggers are created and managed by choosing the Tables object in the Database window and then selecting Triggers from a table's shortcut menu.

  • Replication— You can establish and maintain replication settings that enable the SQL Server database to publish or subscribe to other SQL Server databases. SQL Server 7.0 can also publish data to Jet 4.0 tables. Replication is managed by choosing Replication from the Tools menu.

  • Security— You can create and maintain a security model for the SQL Server database objects and data by choosing Security from the Tools menu.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.191.169