[ Team LiB ] |
Recipe 13.5 Create One File to Store Connection Information for All DAPs in an Application13.5.1 ProblemYou have many DAPs that all use the same data source. The data source's name and location are subject to change; for example, the pages point to a sample data source when you're working on their design and to a production data source when you deploy them. But if you move the data source to a different folder or change the name of the data source, the links your DAPs use will probably break. You'd like to be able to change the data source in one place, rather than making the change on every page. 13.5.2 SolutionStarting with Access 2002, you can use a connection file, rather than a hardcoded string, to define the source of the data for each page. Microsoft provides two types of files for storing data connection information: Microsoft Data Link (also called Universal Data Link, or .udl) files, and Office Data Connection (.odc) files. You can create a data connection file that points to the test data, create and test your pages, and then switch to live data by editing the data connection file. Essentially, both .udl and .odc files store an ADO connection string. We'll walk you through the steps to create and edit each type of file, and then talk about how to reference a connection file in your DAPs. The .udl format has been around longer, so we'll discuss it first. A .udl file is a text file that stores the same provider and data source information you would use to set up an ADO connection. To create a .udl file, follow these steps:
Figure 13-10. The .udl file format uses a simple wizard to create a connection string
The .odc format was new with Office XP. It stores information about the connection in an HTML format and uses the Office Web Components to display information about the database when you view the .odc file in Internet Explorer. To create an .odc file, follow these steps:
Figure 13-11. By default, .odc files are stored in My Data Sources, a subfolder of My Documents
Figure 13-12. The Jet provider falls into the Other/Advanced category
Figure 13-13. The .odc wizard looks just like the .udl wizard at this point
Figure 13-14. You can't select a table at this point
Figure 13-15. Provide a meaningful name and description
If you want to change an .odc file to point to a different location, you'll need to open it in a text editor. Follow these steps to make the change quickly:
Figure 13-16. A portion of the text file in Notepad
To use either type of data connection file to supply the data source for your page, simply set the ConnectionFile property of each page to the name of the connection file. When you set the ConnectionFile property, Access automatically adds the ConnectionString property as well, but the ConnectionFile takes precedence. That is, if the ConnectionFile's information changes, the ConnectionString property will be updated automatically the next time the page is opened. You can use the Pages page of the Tools Options dialog to set a default ConnectionFile property. Then, all new pages will use your connection file as the ConnectionFile property value. |
[ Team LiB ] |