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

May 2005 - Posts

  • 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.

     

  • Tips and Tricks You May or May Not Already Know

    I've been using Visual Studio .NET since it was in short pants, yet I saw something last week I didn't know you could do. I was at the MSDN Event in Lakewood (a suburb of Tacoma, which is about an hour south of Seattle). Rory Blyth was the presenter (and a good one too). I several times saw Rory deleting entire lines of code using nothing but the keyboard. And he wasn't selecting the line of code first. I had no idea how he was doing it. Turns out that if you have the cursor at the beginning of a line of code you can Ctrl-X and the line is cut.

    I did not know that. Is it because I would prefer to use the mouse and only use the keyboard if I have to? Maybe. Is this something everybody knows and I am now the next to last person on the planet to have figured this out? Hope not! There are lots of these little things in the product and I never tire of learning them.

    Here's one you probably don't know. In VS 2005, create a Data Source. Drag a table from the Data Sources window (drag it after specifying Details rather than Grid). You get data bound textboxes (eg CustomerIDTextBox) and data labels (eg CustomerIDLabel). Very nice. Now write some code to change the data labels to red. You can't. Type Me. and CustomerIDTextBox appears, but CustomerIDLabel does not. The following code

    CustomerIDLabel.ForeColor = Color.Red 

    generates an error. CustomerIDLabel is not declared. This is because the GenerateMember property of data labels is set to False when you drag and drop from the Data Sources window. GenerateMember determines whether or not a member variable is created. Change GenerateMember to True for CustomerIDLabel and now the code above is fine and CustomerIDLabel appears in IntelliSense.

     

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