Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Книги_AutoCad_2 / AutoCAD 2006 and AutoCAD LT 2006 Bible_2004г__.pdf
Скачиваний:
142
Добавлен:
09.04.2015
Размер:
17.83 Mб
Скачать

Chapter 20 Working with External Databases

609

A catalog is a collection of schemas and has the same name as the folder where the database is located.

A schema is a set of tables and other database components. It has the same name as the catalog subfolder where the database tables reside.

You don’t need to work with these concepts if your database system does not require or specify it. AutoCAD can connect to an individual table or to a collection of tables stored in an environment, catalog, or schema.

Preparing for Database Connectivity

Database connectivity involves several components that you need to prepare in advance. When they are in place, the connection should go smoothly. In this section, I explain the necessary preparation steps.

The basic steps for starting to work with database connectivity are as follows:

1.Make sure that you have installed the Database feature of AutoCAD.

2.Make sure that you have the ODBC Data Source program from Microsoft.

3.Arrange your database tables into catalogs (folders) and schemas (subfolders) appropriate for your application, if necessary.

4.Configure the appropriate database driver using Microsoft’s ODBC (Open Database Connectivity) or OLE DB programs.

5.Configure your data source from within AutoCAD.

6.Start the dbCONNECT command.

7.Establish a user access name and password, if required by the database system.

8.Connect to your data source.

9.Open the Data View window containing your data table.

10.Edit the data, if desired.

11.Link database rows to objects in your drawing.

12.Create labels based on the data in your drawing, if desired.

Installing AutoCAD’s database feature

If you aren’t sure whether you installed the database feature, open the Tools menu. If you see a dbConnect menu item, then you have installed it. If you didn’t install database connectivity and want to, follow these steps:

1.Close AutoCAD if it is open.

2.Choose Start (Settings ) Control Panel to open the Control Panel. (The steps may vary slightly, depending on your version of Windows.)

610 Part III Working with Data

3.Choose Add or Remove Programs.

4.Select AutoCAD 2006 and click Change.

5.In the AutoCAD 2006 Setup dialog box, choose Add or Remove Features. Click Next.

6.In the next window, click the Database arrow and choose one of the options to install this feature on the hard drive. Click Next.

7.Continue to follow the on-screen instructions to install database connectivity.

Organizing the database structure

To connect to a database, you need to know the type of database-management system that created the database and the structure of the database itself, along with the folders that contain that structure.

In the following exercise, you create a simple structure for a Microsoft Access database table.

Note In this chapter, you cannot do the later exercises without doing the earlier ones. The later exercises depend on the setup and configuration that you create in the earlier exercises.

On the

The file used in the following exercise on creating the structure for the database, ab20-

CD-ROM

prt.mdb, is in the Drawings folder on the CD-ROM.

STEPS: Creating the Structure for the Database

1.Right-click Start on the task bar. Choose Explore to open Windows Explorer.

2.If your AutoCAD Bible folder is not displayed in the Folders window, click the plus sign

(+) next to the drive containing the AutoCAD Bible folder.

3.Click the AutoCAD Bible folder and choose File New Folder from the Explorer menu. A new folder appears in the right window, called New Folder. Type Databases to rename the folder.

4.If necessary, in the Folders window, click the plus sign to open the AutoCAD Bible folder. You should see the new Databases folder. (If not, press F5 to refresh the Explorer view.)

5.From the CD-ROM, copy ab20-prt.mdb to the Databases folder that you just created. Be sure to choose the ab20-prt.mdb file, not the ab20-prt.xls file. The .mdb file is a database of parts. Figure 20-1 shows this database.

6.Because this file is coming from a CD-ROM, you may need to change its read-only property. Still in Explorer, right-click ab20-prt.mdb and choose Properties from the menu. Uncheck Read-Only and click OK.

7.Click the Close button of Explorer to close it.

Chapter 20 Working with External Databases

611

Figure 20-1: The Access database.

Thanks to Gary Morris of the Dexter Company, Fairfield, Iowa, for this database.

Configuring a data source

To start working with external databases, you must tell AutoCAD how to communicate with your database, called a data source. AutoCAD uses ODBC and OLE DB for this communication. AutoCAD provides a sample Microsoft Access file, called db_samples.mdb in AutoCAD’s Sample folder, that you can work with to get started.

First, you must install and configure the ODBC Data Source Administrator. To check if the ODBC Data Source Administrator is installed on your computer, open the Control Panel by choosing Start Settings Control Panel (or as required by your operating system), and look for one of the following items:

ODBC Data Sources (32-bit) or Data Sources (ODBC)

Administrative Tools Data Sources (ODBC)

To check if you have the required drivers installed, double-click the ODBC item. In the ODBC Data Source Administrator dialog box, you’ll see a list of database application drivers. Check to see that your database application is listed. A database driver contains information about how to connect to your database. In most cases, your operating system will include the ODBC Administrator. If you don’t have the ODBC 32-bit Administrator, you need to install the Microsoft ODBC Driver Pack. The ODBC Driver Pack 3.0 (or later) is free from the Microsoft Web site at http://msdn.microsoft.com/data/downloads/default.aspx

612 Part III Working with Data

Click the Product and Update Downloads link. The MDAC Downloads (Microsoft Data Access Components) link should lead you to everything you need.

The instructions to set up the database vary according to the drivers that you use. The AutoCAD online help contains help on all supported databases. Look in Help Help and click the Contents tab. Double-click Driver and Peripheral Guide and then Configure External Databases. Click the Procedures tab and choose the link for your database.

To set up your database using ODBC, follow these steps:

1.From the Windows task bar, choose Start Settings Control Panel.

2.Double-click the Data Sources (ODBC) item. (You may have to double-click Administrative Tools first.) Windows opens the ODBC Data Source Administrator dialog box, shown in Figure 20-2.

3.Click the User DSN tab if it isn’t already displayed. Choose Add.

4.In the Create New Data Source dialog box, choose the driver appropriate for your database and click Finish.

Figure 20-2: Use the ODBC Data Source Administrator dialog box, accessed from the Windows Control Panel, to choose a database driver to connect to your database.

5.In the ODBC Setup dialog box, which is now titled with the name of the driver that you chose (for example, ODBC Microsoft Access Setup), type a name for your data source in the Data Source Name text box. You can also add a description. In general, this name refers to your database program, not the individual database file.

6.Click Select and navigate to the folder containing your database. Choose the database file and click OK.

7.Click OK again in the Setup dialog box.

Chapter 20 Working with External Databases

613

8.In the ODBC Administrator dialog box, your data source is listed with its appropriate driver. Click OK. Close the Control Panel.

You’re now ready to configure your database from within AutoCAD. Follow these steps:

1.Choose Tools dbConnect to open the dbConnect Manager palette and display the dbConnect menu.

2.From the menu, choose dbConnect Data Sources Configure. (The dbConnect menu appears when you start dbConnect.) In the Configure a Data Source dialog box, type a name representing your database file. Click OK.

3.On the Provider tab of the Data Link Properties dialog box, choose Microsoft OLE DB Provider for ODBC drivers. Click Next.

4.From the drop-down list on the Connection tab, choose the name of the data source that you used in the ODBC Setup dialog box, as shown in Figure 20-3.

Figure 20-3: Use the Data Link Properties dialog box to configure your data source within AutoCAD.

5.For server-based databases, enter the user name and password.

6.Click Test Connection. You should see a message saying Test Connection Succeeded. (If not, check your settings as well as the spelling and case of the name of the data source.) Click OK.

7.Click OK in the Data Link dialog box.

You’re now ready to establish a connection between a database and an AutoCAD drawing.

614 Part III Working with Data

On the

The drawing used in the following exercise on configuring a Microsoft Access database,

CD-ROM

ab20-a.dwg, is in the Drawings folder on the CD-ROM. This exercise requires that you

 

have completed the steps in the previous exercises.

STEPS: Configuring a Microsoft Access Database

1.From the task bar, choose Start Settings Control Panel. Double-click the ODBC Data Sources icon. (Your item may have a slightly different name.) If you don’t have this item, double-click the Administrative Tools icon and look for the ODBC item there.

2.On the User DSN tab of the ODBC Data Source Administrator dialog box, choose Add.

3.In the Create New Data Source dialog box, choose Microsoft Access Driver. Choose Finish.

4.In the Data Source Name text box of the ODBC Microsoft Access Setup dialog box, type ab20-Access.

5.Click Select and navigate to your AutoCAD Bible\Databases folder (which you created in the previous exercise). Choose ab20-prt.mdb and click OK.

6.Click OK twice more to exit the ODBC Data Source Administrator.

7.Close the Control Panel.

8.Open AutoCAD. Open ab20-a.dwg from the CD-ROM. Save it as ab20-01.dwg in your

AutoCAD Bible folder.

9.Choose Tools dbConnect to open the dbConnect palette and display the dbConnect menu. From the menu, choose dbConnect Data Sources Configure. In the Configure a Data Source dialog box, type ab20-prt. Click OK.

10.On the Provider tab of the Data Link Properties dialog box (which opens automatically), choose Microsoft OLE DB Provider for ODBC Drivers. Click Next.

11.From the upper drop-down list, choose ab20-Access.

12.Click Test Connection. You see a message saying Test Connection Succeeded. Click OK.

13.Click OK in the Data Link Properties dialog box.

14.Keep ab20-01.dwg open for the next exercise.

Connecting to an Excel Spreadsheet

If you have a database in Excel and want to practice working with Excel, you may use the Excel spreadsheet database on the CD-ROM. Here’s how:

1.Follow the steps in the exercise “Creating the Structure for the Database.” In Step 5, copy the ab20-prt.xls file instead of the .mdb file. If necessary, uncheck the read-only property as described in Step 6.

2.Double-click the ODBC item or Administrative Tools Data Sources (ODBC) in the Control Panel to open the ODBC Data Source Administrator dialog box.

3.On the User DSN tab of the ODBC Data Source Administrator dialog box, choose Add.

Соседние файлы в папке Книги_AutoCad_2