Jason Salas' WebLog

On-air and online: making people laugh, making people think, pissing people off

ASP.NET sites that kick ass

Pals with blogs

Podcasts I listen to

Book review: "Beginning ASP.NET 1.1 E-Commerce - From Novice to Professional"

"Beginning ASP.NET 1.1 E-Commerce - From Novice to Professional"
By Cristian Darie and Karli Watson

Despite the monumental rise and gradual decline in the electronic commerce model, the lessons that one can learn from developing such applications are vast, timeless and applicable in so many more theaters than just payment processing or shopping carts.   Cristian Darie empowers you with the tools and talents you'll need to enable your web applications with simple shopping and fulfillment options.  

The book's primary audience is the beginning to intermediate level ASP.NET developer who has the basics of ASP.NET and Visual Basic .NET programming under their belt.   It reaches out to the low-to-no-budget client who's looking for a high-impact solution without needing to spend huge amounts of capital.  

The book's single application is a practical online storefront with payment processing examples given through both the popular PayPal and via a roll-your-own model.   All the major considerations for running an online store are included, such as the general model for customer fulfillment, developing a custom shopping basket and working with the order pipeline.

The featured app's main driver for presentation is a single WebForm that dynamically loads user controls based on the page's post back state and/or query string values.   I'm personally not crazy about this model of web development, preferring templated independent .ASPX files without so much reliance on the URL and embedded values therein, but that's just me.   Nonetheless, the book leverages such a structural design, and does it well.   And, the tiered nature of the app makes changing the UI easy without breaking the more critical components.   It's a nice variation on a theme.

The main blessing I found in this title (and at the same time the source of its greatest fault) is it's inseparable fit to Visual Studio .NET.   If you're of the crowd who live and die by Microsoft's prime .NET IDE it's great, but for those preferring to painstakingly hand-code their apps or use an alternative setup like ASP.NET Web Matrix and manually compiling assemblies, you're left with no alternative; it's a bit of a stretch to immediately understand the relationships between WebForms and business classes. 

Thankfully the book is a tad more forgiving when it comes to the database server, frequently mentioning the differences between SQL Server and it's more laid back cousin, MSDE.

And further, the web storefront's architecture is beautiful, consistent and easy to read.   You'll benefit from the nicely-laid out 3-tier model used throughout, and while the code isn't explained verbatim, the book emphasizes good object-oriented programming and the use of stored procedures and user-defined functions.   There's especially some really clever ADO.NET and T-SQL syntax even a guru will smile at and save for later use. 

On that note, the book at times doesn't use what many first-generation ASP.NET developers might consider best industry practices and does present a couple of programming tricks which might be up for lively debate, (e.g., passing DataReaders between application tiers), but it does introduce some interesting ways to get things done, albeit in so doing swimming against the generally accepted stream.

But beyond all the good tidbits and tips the book offers, the one shining moment that distinguishes it from most other texts in its genre is evident in the "Searching the Catalog" chapter.   The authors discuss the considerations, concepts and code required to built a (somewhat) scalable, quick and timely internal search utility.   This is one chapter and topic that no ASP.NET developer should go without reading, and the book is well worth the "price of admission" if you will, based on this chapter alone.   If you buy the book for any one reason - e-commerce or otherwise - it would be this chapter.

 However, the only downside I cited to the book's search discussion was the fact that it mentioned using Microsoft SQL Server Full-Text Indexing in principle only, and doesn't exhibit how to build a search tool using FTI.

In short, this book definitively shows how to get a commerce-empowered site up and running quickly and easily with very few enterprise-level tools.   The search chapter is a must-read, and you'll learn much from a structured, methodic approach to ASP.NET development.

Comments

Jeff Coon said:

I've only recently begun my switch from classic ASP to ASP.NET. Can I ask you to elaborate on your statement about best practices when you denounce "passing DataReaders between application tiers"? I haven't yet written a multi-tiered application, as I'm still using VB 6.0 COM components and laying .NET as the presentation layer on top of that. But I'm beginning to envision what that might look like and was wondering why specifically you pointed out this example as something not to do? Thanks Jason.
# September 30, 2004 11:52 AM

TrackBack said:

# September 30, 2004 4:21 PM

Jason Salas said:

Hi Jeff,

In the early days of ASP.NET development (circa 2001), it was generally thought it to be a bad thing way to transfer data in n-tier web applications by passing DataReader objects between the data tier and business tier. This was due to the fact that because DataReaders are fast, forward-only reader, they stay open until explicitly closed by a call to their Close() method at design time.

So if anything were to happen in code, by way of an adverse situation kicking in - like an exception or just negligent programming - the DataReader would pass between tiers, with the reader itself and the underlying database connection still open, unnecessarily occupy a database connection that could be used for better purposes with another user. The .NET Framework would be smart enough to release the connection eventually on its own as a means of housekeeping, but this would usually be to the detriment of the app.

For this reason, it became more advisable to use disconnected DataSets between app tiers. This is because the DataSet.Fill() method not only puts data into the DataSet, but it automatically closes the underlying connection to a data source (typically a relational database).

This became a topic of much debate, and people generally said that it's safer programming to just pass DataSets and leverage their disconnected nature. The only downside is that working with DataSets results in slower performance than DataReaders.

That having been said, I will compliment author Cristian Darie on coming up with an intriguing way of what seems to appear to be safely passing passing DataReaders between a data and business tier. He uses this general construct throughout the middle tier:

SqlConnection conn = new SqlConnection("DB_CONN_STRING_HERE");
SqlCommand comm = new SqlCommand();
try
{
return comm.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(Exception ex)
{
conn.Close();
throw e;
}
finally
{
// do anything else required in code
}

Darie explains how this takes full advantage of the speed of a DataReader, while ensuring to close the database connection should anything unexpected happen. It's a pretty cool concept.

Hope this helped!
# September 30, 2004 7:55 PM

Cristian Darie said:

Hi Jeff,

I’m Cristian Darie, author of “Beginning ASP.NET 1.1 E-Commerce”. I’ve come across this discussion and I’d like to share my opinion on the subject.

So ... I do agree with Jason that passing DataReader objects between application tiers should be discouraged in many circumstances. However, there are circumstances where this solution may prove to be your best option. Let me talk a little bit about both possibilities.

In theory, each application tier should comply to the “black box” concept – every object should communicate with the other objects only through their publicly exposed interfaces, while not being aware of the other objects’ internal workings.

The bad news about passing DataReader objects between application tiers is that it breaks the “black box” principle. The DataReader is indeed the fastest way to read data from your database, but it requires an open database connection to operate. When passing a DataReader object to the presentation tier, you also delegate to the presentation tier the responsibility to close the database connection used by that DataReader. This means that the lower tiers aren’t well protected and independent, since their integrity depends on the presentation tier. The consequences of ill behavior on the presentation tier side can be keeping database resources locked, which can result in a slower (or even malfunctioning) application. This problem is especially sensitive in the context of a web application, where an error that happens in one visitor’s session can result in the application malfuctioning for all the other users.

The good news is that in practice you can trick the system to take advantage of the full power (and speed) of the DataReader, while keeping risks low. Microsoft was smart to offer the CommandBehavor.CloseConnection option (have a look at the code snip provided by Jason), which tells the DataReader to also close its connection when it closes. At the same time, the ASP.NET web controls that take the DataReader object as data source are careful to close the DataReader object immediately after reading its data, thus ensuring the database connection isn’t kept open longer than necessary. These details, combined with a clever error handling strategy, can lead to a very reliable and very fast web application.

In my opinion, the main problem with passing DataReaders is that, in case of complex applications, breaking (even if just for a little bit) the “black box” concept can affect the application’s flexibility and extensibility on the long term. For this reason I would not recommend implementing an architecture based on passing DataReader objects for building large applications. However, I did find this solution to be the optimal choice for building small to medium web applications, such as the one presented in “Beginning ASP.NET 1.1 E-Commerce”.

BTW. the code snip provided by Jason is in C#, although the book actually uses VB.NET.

Regards,

Cristian
# September 30, 2004 10:42 PM

Cristian Darie said:

Jason, thank you very much for the great review! I did enjoy writing the "Search" chapter at least as much as you enjoyed reading it (especially because I couldn't find any other book on the market to present the same information).

I'm the most recent fan of your weblog :)

Cristian.
# October 1, 2004 7:18 AM

Jason Salas said:

Thanks Cristian! Both for the compliment and for helping Jeff with his query!
# October 1, 2004 7:22 AM

Jeff Coon said:

Wow, excellent replies - thank you! I didn't realize when posing the question that DataReaders left the connection to the database open. Knowing that, I understand the reasoning for discouraging passing them between tiers. Were I writing only a single tier responsible for passing data, I wouldn't want to leave it up to another developer to close the connection to my database.

I can envision using the trick you provided to safely pass a DataReader for a personal project where I could be certain the DB connection would be closed, but any such applications I can think of wouldn't have the sort of traffic necessary to warrant the performance boost of a DataReader over a DataSet.

I'm finding the actual programming aspects of .NET fairly easy, but questions like this about best practices are tough to find answers to. I can Google up articles on how to code a DataReader and a DataSet, but it's much harder to find articles explaining when to use one or the other. (actually, it's probably easy for those particular objects, but I was just trying to illustrate a point about finding it hard to find articles on best practices) I guess the best way to learn that is just to keep reading as much as possible and asking questions.

Thanks again for the great replies.
# October 1, 2004 12:10 PM

Jason Salas said:

Jeff, check out the book "ASP.NET Best Practices" or look for articles on DataReader vs. DataSet on MSDN or in ASPAlliance.com. I recall there being several such pieces written on the topic. Most ADO.NET books for ASP.NET will mention this at some point.
# October 1, 2004 7:01 PM

Cristian Darie said:

Jeff,

Good to hear you found the answers helpful. I have just one note regarding your answer. Many decisions you will make about the architecture of your application will be driven by the complexity of your application, and not necessarily about the expected traffic. A small e-commerce website can get much more traffic than a very complex web application with lots of features, etc. That's it, have fun playing with ASP.NET :)

# October 2, 2004 2:43 PM

Dave Burke said:

Great review, Jeff. This may be the next nerd book I should buy. I appreciated Cristian's input here as well, another strong selling point.
# October 4, 2004 10:54 PM

Jeff Coon said:

Ooooh, excellent. Thanks for the best practices book info, Jason. I'll be picking this up at lunch!
# October 6, 2004 11:36 AM

John said:

I've spent years trying to learn ADO.NET and ASP.NET to build an e-commerce site. I can say I've bought plenty of other books and videos - but they were all fragmented, full or errors and difficult to piece everything together.

I must say this book is EXCELLENT!

Christain's attention to detail and explanations is second to none. If there was an Authors Award he would win it hands down.

I am keeping an eye out to see if he writes a book on Visual Basic 2008 ASP.NET E-Commerce.

# March 16, 2008 9:52 PM

Beginning ASP NET 1 1 E Commerce From Novice to Professional | ASP.Net Information and Books Blog said:

Pingback from  Beginning ASP NET 1 1 E Commerce  From Novice to Professional | ASP.Net Information and Books Blog

# September 10, 2008 11:05 AM

Beginning ASP NET 1 1 E Commerce From Novice to Professional | ASP.Net Information and Books Blog said:

Pingback from  Beginning ASP NET 1 1 E Commerce  From Novice to Professional | ASP.Net Information and Books Blog

# November 15, 2008 11:23 PM

driver17 said:

He's a great guy to learn from if you're in Fiction. ,

# October 22, 2009 3:17 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)