Thursday 3 September 2009

Visual Web Developer 2008: Failed to load dataset because of the following error: Unable to find connection

Somehow, I ended up with two connection strings in my ASP.NET project.

I don't know where the second one came from (I suppose it could've been user error), but VSWD called it connectionString1 and without my permission or instruction, modified a whole load of other files in my project to suit. So I just took the sledgehammer approach and removed the second connection string and did a project-wide find and replace on all occurrences of connectionString1.

I thought I was ok until I got to the point where I needed to make some changes to the DAL of the application, and the following error appeared:


The error message isn't exactly self-explanatory and VSWD wasn't exactly helpful.

So I started panicking, sweat coming from my brow at the prospect of having to spend hours at figuring out the source of this problem, feeling stupid because I felt that I had caused this problem by messing about with settings I didn't understand.

I could open the DAL .xsd file in Source mode, but could not open it in Design mode. Hmm... seems to be some issue with all of the stuff VSWD does in the background to render the visual portrayal of your DAL...

Anyway, lo and behold the answer came nice and easily. In my DAL's .xsd file, I had two references to exactly the same connection string. So when trying to load it up it got confused, spat the dummy and didn't bother telling me what the problem was.

So if you see this problem in your project, check to make sure that

1) You don't have multiple connection strings in your project where you don't explicitly need them.
2) You don't have duplicate references to your connection strings in your DAL's .xsd file.

I think that error can be caused by other things, but check those two things first and hopefully it'll help.

0 comments: