XL: How to Use File DSNs and DSN-less Connections
This article was previously published under Q165866 On This PageSUMMARY
When you use a connection string that does not use a data source name (a
DSN-less connection string) to connect to an external data source in
Microsoft Excel, information that is required to connect to the external
data source is stored in the file structure of the workbook instead of in
the data source name. Microsoft Query 97 and later, and Microsoft Excel 97 and later use this kind of DSN-less connection; earlier versions of Microsoft Query and Microsoft Excel do not.
MORE INFORMATIONWhy Are DSN-less Connections Important?In earlier versions of Microsoft Excel, retrieving external data requires that you create a data source. The data source name and other information that is required to connect to the data are stored in hidden names in the worksheet. Therefore, when a workbook that contains references to external data is shared among multiple users, the data source name that is referenced in the connection string must exist on each user's computer. Otherwise, you may receive an error message when you update or edit the external data.In Microsoft Excel 97 and later, once the data is returned to a worksheet, the Structured Query Language (SQL) statement and driver information that is generated from the initial data source (not the data source name) is stored with the worksheet in the file structure of the workbook. These DSN-less connections resolve the issue of maintaining data sources on several computers. All of the necessary information is stored in the workbook itself. However, a copy of the appropriate Open Database Connectivity (ODBC) driver must be installed on each computer for the queries to function. What Does a DSN-less Connection String Look Like?The following is an example of a DSN-less connection string:
DBQ=C:\TEST\QUERY FILES;DefaultDir=C:\TEST\QUERY FILES; _
Deleted=1;Driver={Microsoft dBase Driver (*.dbf)}; _
DriverId=277;FIL=dBase IV;PageTimeout=600;Statistics=0
Note that there are no references to the DSN keyword in the text.
More About Data Source FilesMicrosoft Query version 2.0 stores data source information in the registry. Microsoft Query 97 and later do not use the registry to store data source information. Instead, when you create a new data source, the connection information is stored in a text file with a .dsn file name extension. This file is also known as a File DSN.Each File DSN contains an ODBC section and an optional Microsoft Office section that may contain information, such as the default table, password, and user ID for a given data source. The following is the default folder that is used when you save a File DSNX C:\Program Files\Common Files\ODBC\Data SourcesThe following is the default folder that is used when you save a query: C:\Program Files\Microsoft Office\QueriesYou can specify which folders are included in the search for File DSNs, including network locations. The following is an example File DSN that uses the Microsoft Access 7.0 Database driver (an ODBC driver included with Microsoft Office 97):
When you create a File DSN that references a file that is located on the
network and you map the network drive to a specific drive letter, that
drive letter is specified in the File DSN. This behavior may cause problems
if you want to share the File DSN with multiple users across the network
and you want to maintain the File DSN on a server where all users can
access it. To work around this problem, use either of the following
methods.
Method 1Whenever possible, use a universal naming convention (UNC) reference instead of a mapped drive.Method 2Open the File DSN in Notepad and modify the references to the drive letter to use a UNC reference. Consider the following example:
In this example, <drive letter> is the mapped drive and <source filename> is the source data file.
Change the last two lines to the following
Where <server name> is the network server, <share> is the share on the network server, and <source filename> is the source data file.
After you modify the file, all users can successfully use the File DSN. For more information about the driver information in the File DSN, please see the Help file that is specific to the ODBC driver you are using. You can also use the 32-bit ODBC Control Panel icon to create a File DSN. To do this, follow these steps:
Microsoft Query Information in the RegistryMicrosoft Query automatically registers itself if the path value for Query is missing in the registry key, or if path value specifies a folder that that does not contain the file. You can reset the location for Microsoft Query in the registry by starting Microsoft Query. In Microsoft Windows 95 and later, you can locate Microsoft Query by looking in the following registry key:HKEY_LOCAL_MACHINE\Software\Microsoft\Shared Tools\MSQueryWhen you install Microsoft Office 97 or later, the Setup program creates a registry key that points to the default location for DSN files. This location is stored in the following registry key: HKEY_LOCAL_MACHINE\Software\ODBC\odbc.ini\ODBC File DSN\DefaultDSNDirYou can specify an alternative location for the DSN files by adding the following registry key. HKEY_CURRENT_USER\Software\ODBC\odbc.ini\ODBC File DSN\DefaultDSNDirAfter you create this key, the key under HKEY_LOCAL_MACHINE is ignored. REFERENCES
For 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 Help is not installed on your computer, click the article number below to view the article in the Microsoft Knowledge Base: 120802 (http://support.microsoft.com/kb/120802/EN-US/) Office: How to Add/Remove a Single Office Program or Component For additional information, click the article number below to view the article in the Microsoft Knowledge Base: 159557 (http://support.microsoft.com/kb/159557/EN-US/) XL97: Using System, User, and File Data Sources
APPLIES TO
| Article Translations
|

Back to the top
