There is already an open DataReader associated with this Command which must be closed first.

November 18, 2009 10:25 by bryan

Having been using LINQ to SQL for some time now, I came across my very first issue "There is already an open DataReader associated with this Command which must be closed first." it's been some time since I had this issue.

The issue only appears on one database and that is being held on a SQL 2000 box.

The solution, sorry work around, is to transfer the results in to Lists using ToList() after each LINQ call.

I have found it hard to replicate in my test environment, as it only happens on a clients installation.

David Foderick posted a similar issue he had with the Entity Framework

After speaking with Eric Nelson, he pointed out that SQL 2000 has a lack of support for MARS, however there is no planning to provide support for this, however SQL Azure does not allow MARS. So perhaps this issue will get addressed some time in the future?


How do I create the aspnetdb database?

October 11, 2009 14:06 by bryan

I've been using the Microsoft Aspnetdb database for some time now, and I still get asked about how to create the database, so here you go enjoy:

Microsoft has a new and powerful default database schema in ASP.Net 2.0 as ASPNETDB.mdf database. This database file serves as a role provider, and membership provider. Visual Web Developer 2005 supports the ASP.Net configuration to manage this personal aspnetdb database file within the web application inside the App_Data folder. Aspnetdb database helps in managing users along with their roles e.g. admin, employee, editors etc. It also enables the in-built functionality of Login controls and web parts to be integrated on ASP.Net 2.0 web pages that helps in managing user profiles, login, and personalized user pages very easily even without writing the bulky code to implement the sql queries or stored procedures along with data access code for inserting, updating or deleting the user personalized data.

How to create Aspnetdb database?

Using aspnet_regsql command:

You can use aspnet_regsql command to create aspnetdb database. This command executes the default scripts to create the default database for asp.net 2.0 web applications.

Steps to create aspnetdb database using aspnet_regsql command:

  1. Open the Visual Studio 2005 command prompt from Start --> All Programs --> Microsoft Visual Studio 2005 --> Visual Studio Tools --> Visual Studio 2005 Command Prompt
  2. Type aspnet_regsql and press enter key 
  3. This will open the ASP.Net SQL Server Setup wizard. Click next to continue… 
  4. In the next screen select the option to Configure SQL Server for application services. This option executes a script to configure the database for managing user profiles, roles, membership and personalization. Click next to continue…
  5. In this step enter the sql server name and choose the right authentication method. Leave the database field to default and click next… 
  6. Confirm your settings and click next to finish. 

It's also worth checking out:



Building up an MVC application

June 10, 2009 11:35 by bryan

When you open up MVC out of the box, you get the basic configuration, after a little playing around you soon see areas that require enhancing to, not only make your application more flexable, but also easier to maintain.

Here are a number of additional tasks you can perform that will help with your application.

Which IoC to use?

Don't worry, if you use the Common Service Locator it provides an adstraction over the IoC

How to validate?

I have already covered this one in a previous post, but I'd still go with xVal

Need to generate Themes?

I think it is so important to start correctly and generating the User Interface should be configurable, the easiest way of doing this is to implement a Theme, and Chris Pietschmann has do this for us, Implement Theme Folders using a Custom ViewEngine

Here is a copy of the source for safe keeping.

ASPNETMVC_Preview5_CustomThemeImplementation.zip (226.05 kb)

Need Ajax to work in MVC

Ajax.BeginForm and PartialViews

Extend the UrlHelper

Placing all your assets in one place is not only a good idea, but it also means you can be more flexable if you want to programmically change the theme of your user interface.

 

 

Which can be used like this:

Using Strongtypes and keep away from Strings

It appears so easy with MVC to use String everywhere, just DON'T, generate an extension for the UrlHelper

Now in your view it will look like this

Testing

I've been hit before by Microsofts in build Testing within Visual Studio 2008, great to have this feature built in, BUT, and a big but in order to run the tests you need to have Visual Studio install, so if you try and setup a Continuous Integration server you will also be required to install Visual Studio.

So best to go with what works well and that is nUnit, simple and easy, and more importantly loosely coupled

Mocking

With testing comes Mocking, and which framework do you use?  I also always say keep it simple and easy, so I'm going with Moq, short for "Mock-You", as this is the only Mock Framework that is built around .Net 3.5 and LINQ.

 

 


MVC Release Candidate 1

January 28, 2009 08:40 by bryan

Microsoft have release MVC Release Candidate 1, I've had a little play with MVC and it looks very promising, although it is a different way of programming for your web site, the benefits are huge.

You can download MVC Release Candidate 1 from this link

I'm personally going to wait for our usergroup member to publish his book before I take a leap in to the MVC world.


How to create a Carousel in a webpage

December 22, 2008 10:17 by bryan

The latest fad is to create Carousels to display images, and allow for easy navigation.  I have not been able to find any .NET controls to enable you to create a Carousel on a web page.

 

So I set myself the task of generating a web page control to allow for easy, managed code, configuration of a Carousel Control in .NET

First I went on the hunt for a simple javaScript Carousel that I could use, I found a lovely Carousel by Doug Greenall, the information on his blog goes in to great detail of how the Carousel works, but this was not intention to go in to detail about the inner working of a Carousel.

So I downloaded Doug Greenall's Carousel and then went to adapt the javaScript code to create a single DLL Control that could be reused.

The end product is a small DLL that can be dragged and dropped in to your ASP.NET application or Website

Carousel.dll (21.50 kb)

The project solution was generated using Visual Studio 2008 Pro,with a Target Framework of ".NET Framework 2.0"

Carousel.zip (191.73 kb)

 

How to use the Carousel

Okay, so now I've built the Carousel Control, you now want to to know how to use it?

  • First create a new WebSite
  • Add the Carousel.dll or a project reference to your website
  • On the web page register the control (or add it to your web.config)

  • Then add the control to the page, as seen below

 

  • Next in the code behind you need to add to the CarouselDetail collection, which will add the images, links to the Carousel

 

And that is it, the more you add to the CarouselDetail collection the more items will appear on the Carousel.


Embedding javascript in an assembly

December 22, 2008 10:01 by bryan

I've always been able to create a standalone DLL control that can be reused in other web applications.  I've never really found out how to embed other resources, or more to the point JavaScript files.

Until now

Here's how to embed the file:

  1. Create a js file such as carousel.js
  2. In Visual Studio, select the file in Solution Explorer and change the Build Action property to "Embedded Resource"
  3. Build the project and the carousel.js file is now part of the assembly (you don't need to distibute the js file now it's part of the assembly)

Now to get the resource out using code:

So if we have a resource named Control.carousel.js we can use the following to include it in our page:

System.IO.Stream script = Assembly.GetExecutingAssembly().GetManifestResourceStream("Control.carousel.js");
System.IO.StreamReader sr = new System.IO.StreamReader(script);
Page.ClientScript.RegisterClientScriptBlock(GetType(), "carousel", sr.ReadToEnd().ToString(), true);
sr.Close();
The above code injects the embedded file in to the page, how easy could it be?

 


Membership and Security

November 24, 2008 13:08 by bryan

Always good to go back to basics, where ever I go I have the need to generate a security environment which is based on the MembershipProvider.

There are lots of examples out on the Internet so it makes it hard to find what you are after, everytime I end up back at the same website, as it take you through the basic Membership and then goes in to it in depth, such as switching users if you are an administrator.

Examining ASP.NET 2.0's Membership, Roles, and Profile

Manage Custom Security Credentials the Smart (Client) Way

Not every application is a Web Based application, people still create WinForm application, so if you are using a WinForm application it's worth looking at this article

Using the ASP.NET membership provider in a Windows forms application


Web Testing

November 18, 2008 14:52 by bryan

I'll start this article, and list different ways to perform Web Testing 

Web testing using Fiddler

An old favourite of mine Microsoft Web Application Stress Testing

I am sure there are lots of different Web testing tools, and as I find them I will try and list them here. 

 


Writing to the Event Log from your Application

November 15, 2008 07:20 by bryan

Have you tried to write to the Event Log from within your application?

It's not hard to write to the Event Log these days, in fact .Net makes it quite easy.

Where the issue come is when you deploy your application you find the the operating environment does not have enough permissions.  I found a good article this morning on how to over come this by Rory Primrose

http://www.neovolve.com/post/2008/11/12/Creating-event-log-sources-without-administrative-rights.aspx 

 


ASP.NET MVC Beta Released

October 17, 2008 07:23 by bryan

Microsoft have release for the Beta version of MVC (Model View Control), it has been around in the community preview release for some time and now it is in it's final stages before being fully released.

ASP.NET MVC 

Scott Gu's Release Notes

Free ASP.NET MVC “NerdDinner”

Scott Hanselmann on MVC

You need to make sure you are running Visual Studio 2008 before you even think about using MVC.

It's now time to take MVC as a serious method of development, as it won't be very long before the final offical release is shipped.