.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Patterns in Practice: The Open Closed Principle

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Extending an existing codebase can be as productive and frustration-free as writing all new code when you employ the Open Closed Principle. We'll show you how.

Jeremy Miller

MSDN Magazine June 2008

View Complete Post

More Related Resource Links

Patterns in Practice: Internal Domain Specific Languages


Jeremy Miller explains how internal Domain Specific Languages can help you craft code that is easier to read and write. His bag of tricks to improve your programming includes extension methods, fluent interfaces, object extensions and use of the semantic model.

Jeremy Miller

MSDN Magazine January 2010

Patterns in Practice: Functional Programming for Everyday .NET Developers


This article examines how the new support for functional programming techniques in .NET 3.5 can developers make code more declarative, reduce errors in code, and write fewer lines of code for many common tasks.

Jeremy Miller

MSDN Magazine October 2009

Patterns in Practice: Incremental Delivery Through Continuous Design


The end goal of software projects is to deliver value to the customer. Software design is a major factor in how successfully a team can deliver that value. The best designs are a product of continuous design rather than the result of an effort that tries to get the entire design right up front. This approach lets you strive to apply lessons learned from the project to continuously improve the design, instead of becoming locked into an erroneous design developed too early in the project.

Jeremy Miller

MSDN Magazine August 2009

Patterns in Practice: The Unit Of Work Pattern And Persistence Ignorance


Jeremy Miller continues his discussion of persistence patterns by reviewing the Unit of Work design pattern and examining the issues around persistence ignorance.

Jeremy Miller

MSDN Magazine June 2009

Patterns in Practice: Persistence Patterns


Here we examine data persistence patterns to help you determine which best suits your needs. We look at a number of patterns, including the Active Record, the Data Mapper, the Repository, the Identity Map, the Lazy Loading, and the Virtual Proxy.

Jeremy Miller

MSDN Magazine April 2009

Patterns in Practice: Convention Over Configuration


We look at some techniques you can adopt to reduce the amount of housekeeping code you write so you can focus on the essence of the application.

Jeremy Miller

MSDN Magazine February 2009

Patterns in Practice: Design For Testability


Designing testability into your app means smaller tests that are cheaper to create, easier to understand, faster to run, and much simpler to debug.

Jeremy Miller

MSDN Magazine December 2008

Patterns in Practice: Cohesion And Coupling


Here are some design patterns that allow you to achieve higher cohesion and looser coupling for more flexible, reusable applications.

Jeremy Miller

MSDN Magazine October 2008

Patterns in Practice: Object Role Stereotypes


Object role stereotypes can help you better understand and clarify the responsibilities of the objects in your application.

Jeremy Miller

MSDN Magazine August 2008

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


when i insert record

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

help me.

SqlConnection conn = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=StudentDetails;Integrated Security=True");

SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();

if (conn.State == ConnectionState.Closed)

cmd2 = new SqlCommand("Select * from UserInfo where Standard", conn);
            SqlDataReader dr1 = cmd2.ExecuteReader();
            string stu, par,std,sec,roll;
            par = "";
            stu = "";
            std = "";

ExecuteReader requires an open and available Connection. The connection's current state is closed.


I am accessing SQL2005 with C# code using  OleDbConnection.


A try and catch block catches the following error once a while between the Open() and Close() of the connection:

ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.


I do not even have any idea where to start to debug this.  The ExecuteNonQuery() runs a delete SQL query. It works 99.9% of the time. I do not see anything wrong when this error happens. 


Any hint would be greatly appreciated.



Closed form designer window in VS 2008, now cannot open again



I closed the Form1.Designer.vb tab in VS 2008.  If I click on Form1.vb in the Solution Explorer the View Designer button does not appear.  How can I open the designer window again?

Why do I get: There is already an open DataReader associated with this Command which must be closed



I create a Form and show it:

            JelentesForm jf = new JelentesForm(Globals.DC, (int)row.Cells["Jelentes_ID"].Value);
            jf.StartPosition = FormStartPosition.CenterParent;

The form gets the DataContext (DC) and the ID of row in a table to work with.

In the constructor the form reads the row, then validates it:

            var jel = from j in context.JELENTES where j.Jelentes_ID == Jelentes_ID select j;
            jelentes = jel.Single();


The validating means calling the same stored procedure for the fields to check them. The stored procedure reads data from other tables for checking.

When I open the form first time it is all right. When I close the form (without any action) and open it second time I get the error above in the validateAll() on the first call of stored procedure.

I tried to move the validateAll() from constructor into form_Shown event, then tried to move it into a

There is already an open DataReader associated with this Command needs to be Closed



Hope this subject seems to be familiar in search. I need this subject to be taken for a discussion to get the right solution for me.

My scenario:

I am using  a web service which access the sql server database to provide an XML output. this part is working fine. I am using a SqlDataAdapter and DataTable with Fill method to get the data.


When more than one person access this web service at the same time i get the error message which is given in the subject line.

I understand the problem is because of the sql connection which is still open by the first user. If the first user completes his operation before the second users request then both the user receives the correct response.

My Solution:

What i did was i initiated 10 connection strings and will check which connection string is closed and i have used this connection for the second persons request if they both access at the same time.

My Question:

I know this is not the best solution. So i want to take this topic to be discussed to get a right solution. I am in need of some idea from the experts in this forum to resolve my issue.


Thanks & Regards

Karthikeyan S


Users with permissions cant open or edit form - "The form has been closed"


Dear All,

I am facing this unique problem. Some users in my company's SharePoint portal network despite user permissions, cant open their previous forms or add a new form. Just for testing I also tried giving one of the users full rights, but the problem persists. I am using infopath web based forms.

Following is the error when the user opens up a form:

" Form has been closed"

Upon checking the SharePoint error logs. I found following error message

The form template failed to load. (User: Litware\max.steve, Form Name: Expense, IP": , Request: http://portal/_layouts/FormServer.aspx?XsnLocation=http://portal/hr/Expense/Forms/template.xsn&SaveLocation=http://portal/hr/Expense&Source=http://port

How To Open Fancy Tooltip from GridView

This article will show How To Open show Fancy Tooltip in GridView.

Solidify Your C# Application Architecture with Design Patterns

design pattern can solve many problems by providing a framework for building an application. Design patterns, which make the design process cleaner and more efficient, are especially well-suited for use in C# development because it is an object-oriented language. Existing design patterns make good templates for your objects, allowing you to build software faster. This article describes several popular design patterns you can use in your own applications, including the singleton, the decorator, the composite, and the state classes, which can improve the extensibility of your applications and the reuse of your objects.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend