Welcome to MSDN Blogs Sign in | Join | Help

Managing External Database Connections in Excel 12

Now that we have covered OLAP formulas, I would like to explain a set of work we did in the area of “connection management” in Excel 12 workbooks.  Specifically, I want to show you three new things that you can do in a workbook that is connected to external data (whether that is an Access database, and Oracle database, and Analysis Services cube, etc.).  In Excel 12, you can

  1. see a list of the connections that are used in your workbook;
  2. see where those connections are used; 
  3. change the properties of the connection.

Since the term “connection” has different meanings for different people (especially developers), let me start by explaining what “connection” means in relation to Excel.  Here is our definition: “The information needed to uniquely identify an external data source, and to connect to that external data source, so that some or all of the external data can be imported into Excel 12.”  Put another way, a connection is nothing more than some information – what type of connection this is (i.e. ODBC), the server name (i.e. MyRelationalServer), the table name (i.e. MyTable), optional parameters (i.e. Persist Security Info = True), etc. – that is used by Excel to fetch data for use in Excel (a company’s sales data or inventory data or any other data that a user might wish to bring into Excel).

In the context of Excel, connection information can be stored inside an Excel workbook in what we call a “workbook connection”, or it can be stored in a file of its own, which we refer to as a “connection file.”  Connection files created in Microsoft Office are given a file extension of “.odc” which stands for “Office Data Connection”.  Excel can open .odc files and establish connections based on their contents.  When a connection file is used by Excel 12, all of the connection information is copied from the file into the Excel 12 workbook, resulting in a workbook connection.  Excel then has its own copy of the connection information which it can use to fetch data from the external data source.  When you use Excel’s tools to connect to an external data source, Excel stores the connection information in a workbook connection and, in general, also creates an .odc file which it sticks in your “my data sources” folder.  The theory here is that next time you want to connect to the same data source, you can just open that file and avoid the hassle of re-typing all the connection information into dialogs.  Note that nothing in this paragraph is new to Excel 12 – it all exists in current versions of Excel.

That’s a lot of abstract nouns.  To summarize, we have the following items:

  • External Data Source – a separate database or data file 
  • Connection Information – info needed to connect to external data 
  • Connection File – standalone file containing Connection Information
  • Workbook Connection – copy of Connection Information within an Excel workbook

Now for the interesting part – let’s look at workbook connections in Excel 12 (this is the new part).  In Excel 12, we have added a new dialog that shows all the workbook connections that can be found within the current workbook.  You can get to this dialog from the Data tab by clicking on the word “Connections”.  Here’s a shot of the Data tab.


(Click to enlarge)

The dialog that comes up will look empty when there are no connections in the current workbook, like this.


(Click to enlarge)

When there are several connections in the workbook, it will look like this.


(Click to enlarge)

Note that each connection in the workbook has a name that must be unique (within the workbook).  You can see where a connection is used by selecting it and then clicking on the link in the bottom half of the dialog, like this:


(Click to enlarge)

You can also get to a lot more specific information about a connection, by selecting it in the top part of the dialog and then clicking on the button labeled “Properties…”.  This will bring up the Connection Properties dialog which looks like this:


(Click to enlarge)

This dialog has two tabs.  The first tab, labeled “Usage” is shown above and has settings for how the connection is used within this workbook.  The second tab, labeled “Definition” is shown below and has settings that define the connection information itself.


(Click to enlarge)

The button labeled “Export Connection File…” can be used to save the connection information into an external connection file with a file extension of “.odc”.

The ability to view all of the connections in a workbook in a central location and then to manage those connections with a standardized dialog is new in Excel 12.  In previous versions of Excel, connection information was stored with the object that used the connection.  For example, the connection used by a query table was stored with that query table and the connection used by a pivot table was stored with that pivot table.  In order to browse all the connections in a workbook, you had to navigate, via code, to each of the objects in the workbook that might be bound to external data and then look at the object model for each of those objects to see the connection information.

By providing a centralized place for browsing and managing connectivity to external data, it becomes much easier to make changes such as these:

  • Switch between a test database and a production database
  • Update a connection to point at a different server
  • Update a connection to use a different query string
  • Share a connection among multiple pivot tables

With the introduction of CUBE functions in Excel 12, the need to maintain connections became greater, as the connection to a particular OLAP cube must be specified in each of the CUBE functions.  Additionally, we had received a lot of feedback from customers over the years that changing connections on QueryTables and PivotTables was too difficult.  Hopefully, the work described above does a good job of addressing customer needs.

Published Thursday, February 16, 2006 9:19 PM by David Gainer

Comments

# re: Managing External Database Connections in Excel 12

Friday, February 17, 2006 4:44 AM by Paul Morriss
Can you explain what you mean by "Note that nothing in this paragraph is new to Excel 12 – it all exists in current versions of Excel." I've got Excel 2000 and it doesn't know about odc files.

Do you mean that the concepts aren't new, but that all the stuff (like the connection string, and which cell the datasource is linked to) have been hidden away?

BTW isn't it called something new now, not Office 12? :-)

This is yet another great feature, thanks for including it. We've had to use Excel macros to get at the connection string before now.

# re: Managing External Database Connections in Excel 12

Friday, February 17, 2006 12:00 PM by Bill Schanks
For anyone needing to manage QueryTable's here is an Add-in that has come very handy:

http://www.dicks-blog.com/archives/2005/11/29/query-editor-add-in/

# re: Managing External Database Connections in Excel 12

Friday, February 17, 2006 5:02 PM by Rob van Gelder
Bill: Thanks for posting a link to my Query Editor Add-In.

One of the gripes I have with External Data is that it's not possible to supply Parameters for OLEDB query tables, though it IS possible for ODBC.
The error messages tease me. They all suggest that the OLEDB Parameters are possible, but I supplied the wrong syntax. I spent hours trying various methods without success.

OLEDB querytable Parameters will still not be supported in Excel 12 as posted by David some weeks back.

It all seems backward since OLEDB is the newer technology.

And, what is annoying is that if an MS developer took a look, they'd probably find that filling this gap would be a quick job.

So for now, I recommend sticking with (the older) ODBC.

# re: Managing External Database Connections in Excel 12

Friday, February 17, 2006 7:09 PM by David Gainer
Howdy,

Paul, good points.  ODCs were introduced in 2002, so I should have said 2002 and 2003 to be precise.

Rob, thanks for the feedback.

# re: Managing External Database Connections in Excel 12

Saturday, February 18, 2006 3:49 AM by video
It help me a lot.thanks.

# Excel 2007 charting UX design

Friday, July 14, 2006 6:31 AM by Alex Barnett blog
Sander Viegers is a user experience (UX) designer in the Office Design Group who contributed to Excel...

# Excel 2007 charting UX design

Friday, July 14, 2006 6:36 AM by Alex Barnett blog
Sander Viegers is a user experience (UX) designer in the Office Design Group who contributed to Excel...

# Excel 2007 charting UX design

Friday, July 14, 2006 6:36 AM by Alex Barnett blog
Sander Viegers is a user experience (UX) designer in the Office Design Group who contributed to Excel...

# Switching Data Sources in Excel 2007

Wednesday, December 12, 2007 6:25 PM by Microsoft Excel

Today’s Author: Howie Dickerman, a program manager on the Excel team. Howie is going to discuss different

New Comments to this post are disabled
 
Page view tracker