Create a Reusable Connection to External Data

Một phần của tài liệu Sử dụng Excel thiết lập cơ sở dữ liệu (Trang 136 - 139)

Chapter 7: Automate Repetitive Database Tasks

5.1 Create a Reusable Connection to External Data

If you find yourself connecting repeatedly from several Excel workbooks to data in a specific database, you can create a reusable connection to that data. Over time, this approach is more efficient than specifying the same connection information each time you want to connect to the same data.

117

C H A P T E R 5

■ ■ ■

Quick Start

To create a reusable connection to external data, do the following:

1. In Excel 2007 click Data ➤Get External Data ➤Existing Connections, and then click Browse for More. In Excel 2003, click Data ➤Import External Data ➤Import Data.

2. Click New Source.

3. Follow the onscreen directions to import the data into the current Excel workbook and create the connection file during the import operation. This connection file can be reused during subsequent import operations.

How To

To create a reusable connection, do the following:

1. In Excel 2007 click Data ➤Get External Data ➤Existing Connections, and then click Browse for More. In Excel 2003, click Data ➤Import External Data ➤Import Data.

2. Click New Source.

3. In the What Kind of Data Source Do You Want to Connect To list, make one of these selections:

• If you select Microsoft SQL Server, Microsoft SQL Server OLAP Services, or Microsoft Data Access – OLE DB Provider for Oracle (in Excel 2007) or Oracle (in Excel 2003), Excel will ask you to provide the server name and logon credentials.

Excel will then ask you for additional connection information based on the selected database type.

• If you select Microsoft Business Solutions, Excel will ask you to provide the computer name or URL to where the accompanying data retrieval service (a Web service installed on Windows SharePoint Services for connecting to and retrieving data) is located. Excel will then ask you for additional connection information based on the selected computer name or URL.

• If you select ODBC DSN, Excel will ask you to select an available ODBC driver type or data source name such as dBASE files, Excel files, or MS Access Database. Once you select an available ODBC driver type or data source name, the Data Connec- tion Wizard will ask you for additional connection information depending on the selected ODBC driver type or data source name.

• If you select Other/Advanced, Excel will ask you to select an available OLE DB provider. Once you select an available OLE DB provider on the Data Link Proper- ties dialog box’s Provider tab, click Next. The Data Link Properties dialog box will ask you for additional connection information on the Connection tab depending on the selected OLE DB provider.

4. After you supply Excel with the requested connection details, click OK or Next depending on the displayed dialog box. The Save Data Connection File and Finish page appears.

5. In the File Name box, type a name for the connection file. Click Browse to save the connection file to a specified location.

6. Depending on the selected data source, Excel may ask for additional connection infor- mation, or Excel may ask you to import the associated data directly into the current workbook.

After you finish importing the data, the connection information is saved as a reusable connection with the file extension .odc.

Once you create a reusable connection, reusing the connection file is straightforward:

1. In Excel 2007, click Data ➤Get External Data ➤Existing Connections. In Excel 2003, click Data ➤Import External Data ➤Import Data.

2. Browse to and select the connection file, and click Open.

3. Follow the onscreen directions to finish importing the external data into the current Excel workbook.

Try It

In this exercise, you will practice creating a reusable connection to a Microsoft Office Access database file. You will use the connection file to connect to the same Access database from two separate Excel worksheets.

Create the reusable connection file:

1. Start Excel.

2. With a new blank worksheet visible, in Excel 2007, click Data ➤Get External Data ➤ Existing Connections, and then click Browse for More. In Excel 2003, click Data ➤ Import External Data ➤Import Data.

3. Click New Source.

4. In the What Kind of Data Source Do You Want to Connect To, select ODBC DSN, and click Next.

5. In the ODBC Data Sources list, select MS Access Database, and click Next.

6. Browse to and select the ExcelDB_Ch05_01_04.mdb file, and click OK.

7. Clear the Connect to a Specific Table check box, and click Next.

8. In the Description box, type Alaska Fish Counts and World Populations.

9. In the Search Keywords box, type Alaska fish counts world populations, and click Finish.

10. Click Cancel.

C H A P T E R 5 ■ C O N N E C T TO OT H E R D ATA B A S E S 119

Use the connection file to connect to the same Access database from two separate Excel worksheets:

1. With the Sheet1 worksheet tab of the new blank worksheet selected, in Excel 2007, click Data ➤Get External Data ➤Existing Connections. In Excel 2003, click Data ➤ Import External Data ➤Import Data.

2. Select the ExcelDB_Ch05_01_04 connection file, and click Open.

3. In the Select Table dialog box, select AlaskaFishCounts, and click OK.

4. With the Existing worksheet option selected, click OK.

5. Click the Sheet2 worksheet tab, and in Excel 2007, click Data ➤Get External Data ➤ Existing Connections. In Excel 2003, click Data ➤Import External Data ➤Import Data.

6. Select the ExcelDB_Ch05_01_04 connection file, and click Open.

Note In Excel 2007, make sure to select the ExcelDB_Ch05_01_04 connection file listed in the Connec- tion Files on This Computer section. If you select the ExcelDB_Ch05_01_04 connection file listed in the Connections in This Workbook section, you will not be able to complete the next step.

7. In the Select Table dialog box, select WorldPopulations, and click OK.

8. With the Existing worksheet option selected, click OK.

Một phần của tài liệu Sử dụng Excel thiết lập cơ sở dữ liệu (Trang 136 - 139)

Tải bản đầy đủ (PDF)

(245 trang)