Showing posts with label visual studio web developer 2008 express. Show all posts
Showing posts with label visual studio web developer 2008 express. Show all posts

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.

Thursday, 13 August 2009

ASP.NET: Adding a simple Ajax Web Service with AutoCompleteExtender in Visual Studio 2008 Express

I'd been really struggling to get any kind of Ajax functionality in my ASP.NET project. The first problem was that I couldn't be sure if I had enabled the Ajax extensions in my project, so to verify it I decided to try to create a new 'ASP.NET Ajax Enabled Web Site' template in Visual Studio.

But I couldn't see that option, and wondered if I had the wrong version of the .NET framework installed. No - that was fine, I had 3.5. So it must be something else. Until I discovered that Visual Studio 2008 Express automatically adds the Ajax extensions to any new ASP.NET project you create in it. So that's good.

But when I went to add an AutoCompleteExtender to my ASPX page, I couldn't see the control in my Toolbox. This was odd. But EVENTUALLY I discovered that I was missing the AjaxControlToolkit.dll from my project's Bin folder. This comes as part of the Ajax Control Toolkit, which you can download from CodePlex:



So I downloaded the Binary package (to avoid all the extra crap that comes with it) and dropped the AjaxControlToolkit.dll into the Bin folder of my Project. Then I right-clicked on the Toolbox in VS2008 and selected Choose Items. Selecting the DLL file now meant that after a couple of seconds of chewing it over, the Ajax controls I needed appeared in the Toolbox.

Now I had to see if I could get an extremely simple Ajax control set up on my page, just to see if it was working. So I dragged a new texbox onto my page, gave it a name and then dragged a ScriptManager control onto the page. Next, I had to add an AutoCompleteExtender control which would target the text box I chose, and Ajax enable it.

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ServiceMethod="HelloWorld" ServicePath="WebService.asmx" TargetControlID="TextBoxAjax"> </cc1:AutoCompleteExtender>

So now I have an Ajax enabled control on my page, and finally I needed to set up a web service to feed it something. So I created a new web service called WebService.asmx and added the following code to it:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function HelloWorld(ByVal testStr As String) As String()
Dim returnString(2) As String

returnString(0) = "one"
returnString(1) = "two"
returnString(2) = "three"

Return returnString
End Function

End Class

It creates a WebService.asmx.vb file too, which actually contains the code above. So all the HelloWorld function does is return a string array to the Ajax textbox.

I built and started the app, and voila - when I type something into the box, the values 'One','Two','Three' appear below. It's not smart at all at this point, since the web service just returns those values no matter what is typed into the text box. But it's square one, and it's a good place to start.


Next step, add some proper code to the Web Service which returns the correct autocomplete values based on what's typed.