in

MCW Technologies' Community Server

Downloads, blogs, forums, and more

Adventures in Visual Studio Development

Making Visual Studio easier to use, one blog entry at a time

Object Reference Not Set Hell

I dragged a DataAdapter onto a form today, using VS 2003. I've done this 1000 times before. Up popped the Data Adapter Config Wizard. I chose Next. And then I got the following:

Error Message: Object reference not set to an instance of an object.
Call Stack: at Microsoft.VSDesigner.Data.VS.VsConnectionManager.CheckConnection(Int32 index, ProviderNameInfo nameInfo)

I tried it again a couple times. I exited VS and came back in. I restarted the computer. I always got the same message. My reaction cycled from confusion to panic to abject horror and back.

The VS IDE is very component based. The designers are supplied by various teams and they use components from other teams. Before and during Whidbey Beta 1, this message appeared often at design time, and it often meant that a designer could not use a component it expected to use. In Beta 2 there should be much fewer of these issues. But I'm not using Whidbey. I'm using VS 2003 why is there anything wrong with the Data Designers? What has horked my system? I don't know. So I repaired VS. Same. I uninstalled and reinstalled. Same. I Googled this and found several posts on forums. One person said they had this and then created a new user and the issue disappeared. I did that and the very first time I tried everything worked fine. But then the problem appeared again.

And that (hours later mind you) is when I began to suspect that maybe the problem wasn't with my VS install. It then took less than 10 minutes to find the culprit: a bad data connection.

Here's how to repro what happened to me. I was trying to use the Jet OLEDB Provider to connect to an Excel spreadsheet.

1. In the Server Explorer, select Connect to Database.
2. In the Provider tab, select Microsoft Jet 4.0 OLE DB Provider.
3. In the Connection tab, enter the location and name of the spreadsheet in the database name textbox.
4. In the All tab, add "Excel 8.0" to the Extended Properties. 
5. Click OK twice.

The connection is now in the Server Explorer.  And you can expand the Tables node and see the Worksheets. You can even Retrive Data from Table and see the data.

6. Now drop a SQLDataAdapter from the Toolbox onto the form.

You get the same error message I was getting. Delete the connection from the Server Explorer and all is well again. The error occurs as the Wizard is putting together the drop down list of existing connections. The connection to Excel, even though it works in the Server Explorer, isn't acceptable to the Wizard. So the Wizard pops up the Object reference error and you are left to your own devices to figure out what the problem is.

I won't turn this into a rant on this error, which tells me nothing and led me to waste several hours trying to fix Visual Studio. I'll just share the story with you and hope that future versions of VS do a better job of telling us what is going on.

 

Comments

 

Yannick Tellier said:

Thanks for the story.

October 29, 2007 11:40 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
© Copyright MCW Technologies, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems