XL97: Using System, User, and File Data SourcesLast reviewed: February 27, 1998Article ID: Q159557 |
The information in this article applies to:
SUMMARYMicrosoft Office 97 contains Open Database Connectivity (ODBC) drivers that you can use to access data from other programs. This article describes the different types of data source names (DSN) that you can install and use in Microsoft Office 97 programs, specifically in Microsoft Excel 97.
MORE INFORMATIONWhen you install Microsoft Office, an ODBC icon, which represents the ODBC Manager, is installed in the Microsoft Windows Control Panel. The ODBC Manager allows you to set up and configure ODBC data sources. In the ODBC Manager, you can set up and configure the following three types of DSNs:
User DSN System DSN File DSN User DSNThe User DSN is a data source that is user specific. A User DSN is stored locally but is available only to the user who creates it. User DSNs are not used by Microsoft Query 97. If you use Microsoft Jet, ODBC, or Structured Query Language (SQL) commands and bypass Microsoft Query, User DSNs are required. User DSNs are stored in the Windows registry under the following key:
HKEY_CURRENT_USER\Software\Odbc\Odbc.ini\Odbc Data sources System DSNUnlike a User DSN, a System DSN is not user specific. A System DSN is stored locally and is not dedicated to a particular user. Any user who logs on to a computer that has permission to access the data source can use a System DSN. Some programs, such as Microsoft SQL Server or Microsoft Internet Information Server (IIS), require a System DSN. This DSN must be created on the server where the program is located. System DSNs are stored in the Windows registry under the following key:
HKEY_LOCAL_MACHINE\Software\Odbc\Odbc.ini\Odbc Data sources File DSNThe File DSN is created locally and may be shared with other users. The File DSN is file based, which means that the .dsn file contains all the information required to connect to the data source. Note that you must install the ODBC driver locally to use a File DSN. Microsoft Query uses File DSNs but Microsoft Jet and ODBC do not use File DSNs. The File DSNs are stored by default in the Program Files\Common Files\Odbc\Data Sources folder. File DSNs are not stored in the Windows registry. The .dsn file is a text file that you can view in any text editor, such as Microsoft Notepad. NOTE: When you connect to an existing data source using Microsoft Query, only the available File DSNs that are stored on that computer are displayed. Microsoft Query does not display User or System DSNs. However, you can create a File DSN that points to a System DSN. To create a File DSN that points to a System DSN, use the following steps:
Sample Macro to Return External Data to Microsoft ExcelMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. The following Microsoft Excel Visual Basic for Applications macro can use an existing User or System DSN to retrieve data from a database and store the data in a worksheet. The sample DSN that is used in this macro is MyDSN. It references the Microsoft Access 97 sample database Northwind.mdb in the Program Files\Microsoft Office\Office\Samples folder. You can use MyDSN as a User or System DSN but you cannot use it as a File DSN.
Sub Get_Data() 'Define SQL query string to get the CategoryName field from 'the Category table. sqlstring = "SELECT CategoryName FROM Categories" 'Define connection string and reference File DSN. connstring = "ODBC;DSN=MyDSN" 'Create QueryTable in worksheet beginning with cell C1. With ActiveSheet.QueryTables.Add(Connection:=connstring, _ Destination:=Range("C1"), Sql:=sqlstring) .Refresh End With End Sub REFERENCESFor more information about retrieving data, click the Office Assistant, type "data sources", click Search, and then click to view "Ways to retrieve data from an external database." NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Excel Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q120802 TITLE : Office: How to Add/Remove a Single Office Program or Component |
Additional query words: 8.0
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |