Why is this page text-only?

Results tagged “ASP.NET” from Code Scene

Book Review: ASP.NET 3.5 Unleashed by Stephen Walther

A while back I posted a review of Stephen Walther's ASP.NET 2.0 Unleashed. It's a fantastic book that I've used more times than I can count. The release of the .NET 3.5 framework means there are lots of new things to learn. Thankfully, Mr. Walther has released an amazing follow up-book titled ASP.NET 3.5 Unleashed.

At 1890 pages this book has just about everything you need to know to start building complex ASP.NET applications. While the book assumes that you have some familiarity with using ASP.NET the first few chapters are still devoted to the basics. I encourage everyone to read them, even the experts. There are many tips and tricks in the book so you may learn something new or pick up on something you'd long forgotten. Did you know the asp:Literal control has a build in Mode property that can be set to HTML encode it's content? I'd honestly forgotten about that and had been doing my encoding on the back-end.

This book provides an in-depth look at just about all of the core ASP.NET features building on many of the techniques we used in 2.0. For the new features specific to ASP.NET 3.5 , Walther devotes an entire chapter to the new ListView and DataPager controls. These controls can be thought of as a GridView or Repeater on steroids. There's also a chapter on data access with LINQ to SQL and a 3-chapter section devoted to working with AJAX.NET and the AJAX Control Toolkit.

There are many books out there that focus on the "how" but what I like most about Mr. Walther's books is that he devotes a great deal of time to the "why". For example, the book explains how to use the SqlDataSource control but then also explains why you'll want to avoid it for most complex applications and use the ObjectDatasourceControl instead. With this book you'll not only learn how to get things done, you'll learn how to get things done right. For that reason it's an invaluable resource for your library. Every ASP.NET developer should have this book on his/her shelf.

Note: While the code samples in the previous 1.1 and 2.0 Unleashed books were written in VB.NET, this new 3.5 book has them written in C#. Walther cites the fact that there are now more C# developers than there are VB.NET developers as the reason for the switch. I would've liked to have seen two different versions of the book but all code samples are also provided in VB on the included CD-ROM so everyone can easily follow along.

ASP.NET "Failed to enable constraints" dataTable error

I'm building an ASP.NET application this weekend and ran into the following error.

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

The error message itself is somewhat vague and it took me a little while to troubleshoot it so I thought I'd post my solution here. There are many reasons you could get this error, the most obvious being that you may have data in your database that contains a null value or that violates a foreign-key constraint.

I spent a while checking my database and everything seemed to be in order. There were no null values where there shouldn't be, my relationships were setup properly, and I'd double-checked that I wasn't enforcing foreign-key constraints.

After wracking my brain for a while, I started Googling and found some suggestions in a few different .NET forums which helped fix the problem. It turns out that during my data-importing I'd decided to change a field in one of my tables from VARCHAR(50) to VARCHAR(100) because some of the data was larger than I'd originally expected. However, I'd neglected to update the MaxLength property of the same field in my DataSet file. This disparity is what caused the problem. Updating the MaxLength property to 100 instantly fixed the issue.

So this error message can be somewhat misleading. If you find yourself faced with this error and you've checked all the things that the error message suggests and you're still having problems, check to see that the sizes of your database fields match the sizes in your dataset.

Convert VB to C# or C# to VB

I usually code my ASP.NET pages using Visual Basic. When I'm googling for answers to a tricky .NET problem though, about half of the code samples I find are written in C#. I'm familiar with C# but it's not my native language so deciphering it and converting it takes time, which is a luxury that we developers very rarely have. So what can we do?

The wonderful people at Telerik have created an online code converter application which can take C# and convert it to VB (or vice-versa) for you in seconds. I've been using it all day and it does a pretty good job and can definitely save you a lot of time.

If you're a .NET developer this is definitely a tool that you need in your toolbox. Visit http://www.codechanger.com and bookmark it right now. I guarantee it will come in handy.

VS 2008 JavaScript Intellisense

I don't like being the type of blogger that writes a post that simply links to someone elses post.  Today though, I'm doing just that because:

  • I'm way too busy at the moment to write original content
  • I just think this is awesome
 

If you're an ASP.NET developer and you're not already reading Scott Guthrie's blog, start.  Seriously, go add the RSS feed to your reader right now.

His latest post on Visual Studio 2008 JavaScript Intellisense is great and very exciting if you're like me and don't particularly like writing javascript.  I honestly never learned javascript as well as I should have and until recently have avoided it wherever possible. Now that AJAX has taken the dev world by storm, avoiding javascript is no longer really possible.  Thankfully, VS2008 promises to make the learning curve a lot easier by providing the same type of helpful intellisense that we already know and love from writing .NET code.

It will work for in-line scripts as well as external .js files.  Writing and debugging javascript is about to get a whole lot easier.

Live from Redmond

This is just a quick post to highlight the fact that Microsoft is hosting a bunch of free live webcasts on all things ASP.NET starting August 2nd. They'll be hosted by industry experts such as Joe Stagner and Stefan Schackow and will highlight all sorts of things like security, scalability, Atlas, and more.

These will no doubt contain a great deal of useful information so be sure to register ASAP

Live ASP.NET Webcasts

Book Review: ASP.NET 2.0 Unleashed by Stephen Walther

I'm a huge Stephen Walther fan. Having read his other books I was eagerly awaiting the arrival of this latest edition. Microsoft has made some serious upgrades to the .NET framework since version 1.1 and while these improvements are great, they do require a lot of time to learn. At almost 2000 pages, ASP.NET 2.0 Unleashed is the most complete reference book on the market.

While there's no specific section on what's new in 2.0, this book provides an in-depth look into just about everything that's possible with the ASP.NET framework.

The new data access controls such as the GridView and SqlDataSource are discussed in detail. Building a proper architecture with data access, business logic, and presentation layers is also covered.

Master Pages, caching, web parts, login controls, etc., etc. There are no stones left unturned in this book. All of the chapters in the book have extensive examples (not just code snippets) which you can actually use in your projects. They're also written in both VB.NET and C#.

Stephen also has a great, easy-to-read writing style which makes this book even better. This book is an absolute must have for any developer working with ASP.NET 2.0.

Importing Excel into SQL using ASP.NET 2.0 and SqlBulkCopy

We were recently faced with a challenge at work where the client wanted to provide an Excel file of data which could be imported into SQL and used to update data within certain tables. While this is a snap via Enterprise Manager, it's trickier when the client wants it all to happen on the back-end so they can do it themselves via a web form.

While there are numerous tutorials for exporting data into Excel format, there didn't seem to be many on how to get the data in, so I'm posting this function in the hopes that it helps someone else.

I've stripped out most of the code so that this is JUST the part that imports the data from Excel. This example assumes that the.xls file is already on your server in the same location as this script. You can write your own upload functions to get it there. (If you need help with uploading, let me know and I'll post an article on that as well) This also assumes that you have a table in SQL that matches the schema of your spreadsheet.

This uses the new SqlBulkCopy class in ASP.NET 2.0 which lets you easily copy bulk amounts of data from one source to another.

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Web.Configuration

...

'Declare Variables - Edit these based on your particular situation
Dim sSQLTable As String = "TempTableForExcelImport"
Dim sExcelFileName As String = "myExcelFile.xls"
Dim sWorkbook As String = "[WorkbookName$]"

'Create our connection strings
Dim sExcelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sExcelFileName) & ";Extended Properties=""Excel 8.0;HDR=YES;"""
Dim sSqlConnectionString As String = WebConfigurationManager.ConnectionStrings("MyConnectionString").ToString

'Execute a query to erase any previous data from our destination table
Dim sClearSQL = "DELETE FROM " & sSQLTable
Dim SqlConn As SqlConnection = New SqlConnection(sSqlConnectionString)
Dim SqlCmd As SqlCommand = New SqlCommand(sClearSQL, SqlConn)
SqlConn.Open()
SqlCmd.ExecuteNonQuery()
SqlConn.Close()

'Series of commands to bulk copy data from the excel file into our SQL table
Dim OleDbConn As OleDbConnection = New OleDbConnection(sExcelConnectionString)
Dim OleDbCmd As OleDbCommand = New OleDbCommand(("SELECT * FROM " & sWorkbook), OleDbConn)

OleDbConn.Open()

Dim dr As OleDbDataReader = OleDbCmd.ExecuteReader()
Dim bulkCopy As SqlBulkCopy = New SqlBulkCopy(sSqlConnectionString)

bulkCopy.DestinationTableName = sSQLTable
bulkCopy.WriteToServer(dr)

OleDbConn.Close()

NOTE: I left out any error handling functionality for the sake of brevity but it would be a good idea to use a Try/Catch block to handle any exceptions

AJAX-Enabling a GridView Control with Atlas

In my last post, I pointed out some of the problems with AJAX. In this post, I'll show you to take the ASP.NET GridView control and AJAX-enable it in about 30 seconds using Microsoft's new Atlas framework.

The GridView control is one of the most powerful and commonly used components of the .NET framework. With it, we can easily display data from a datasource such as SQL Server and enable things like sorting, editing, paging, and deleting. All of this can be done with little or no code. Every time you execute a GridView function (such as switching pages) a postback occurs and the entire page reloads. Wouldn't it be great if we could update the GridView dynamically without the need for a postback every time?

The Atlas framework makes this not only possible, but extremely simple.

Step 1 – Download and install the Atlas Framework

Step 2 – Create a new Atlas project and make a new web form with a GridView control bound to a datasource. The Northwind database will work well for this.

Step 3 – Add an Atlas ScriptManager Control to the page and enable partial rendering.

<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />

Step 4 – Surround your GridView control with an Atlas UpdatePanel conrol.

<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
   <ContentTemplate>
      <asp:GridView ID="GridView1" runat="server" ... />
   </ContentTemplate>
</atlas:UpdatePanel>

Step 5 – Save it. Run it. Marvel at how simple that was.

The Problems with AJAX

AJAX is the latest industry buzz-word and to hear people talk you'd think it'd have to be the best thing since sliced bread. I'll go on record as saying that I think AJAX is awesome but, since every other article touts how amazing it is, I'd like to play devil's advocate and point out a few of it's flaws.

JavaScript - AJAX functions entirely by using lots of client-side JavaScript to send requests to the server and update data on the page. No JavaScript means that none of your cool functionality works at all. Providing a non-AJAX alternative may require a lot of extra work.

The Back Button - This is fairly similar to what happens with Flash sites. The user does something, does something else, then wants to return to the previous task so they click the back button. When you're serving normal HTML pages this works great. In an AJAX application however, the back button is essentially rendered useless.

Analytics - Having standard HTML pages provides an easily mechanism to track what your users are doing. AJAX slightly complicates this by replacing some of the pages with asynchronous JavaScript calls. While not impossible, it does have the potential to add a layer of complexity to capturing analytical data. I should note however, that there are companies such as Crazy Egg that are actively working to solve this problem.

Accessibility - Having pages that rely heavily on JavaScript and updating dynamically has the potential to wreak havoc on screen reader type programs for users with visual impairments.

Search Engine Optimization - At this time it may be difficult for search spiders to properly index content returned through complex AJAX updates.

Pasting a Link - The page updates frequently but the address bar never changes. When you cut and paste the link to your buddy, they just see the homepage instead of the info you intended. (Google Maps solves this nicely with a 'Link to this Page' button that updates the URL)

I'm certainly not trying to discourage AJAX use as none of these issues is insurmountable. As with all new technologies however, I would encourage caution and careful consideration before deploying. It's important to understand why you're using the technology instead of using it just to brag that you built an AJAX site. Remember when everyone had to have an all-Flash site, or crazy DHTML? That was the cool thing to do but people quickly learned that it wasn't always the right thing to do. I would urge people to remember that lesson and use the same caution here. AJAX is a fantastic technology and can be greatly beneficial when used properly. Let's do our best to ensure that it stays that way.

I'm out of town for a few days but after that I'll be back with some code samples on how to do some pretty neat things using ASP.NET 2.0 and Atlas.

DevConnections - Day Four

I'm posting this from the Orlando International Airport which apparently has free wireless internet access. That's just fantastic. DevConnections is officially over. Here's my take on the last day.

Session 1 - Managing Memberships and Roles
One of the things ASP.NET 2.0 was designed for was to increase productivity and save developers time. To that end, Microsoft has added a suite of controls and components that allow for easily setting up login forms, creating users, managing permissions, etc. These components and methods take much of the work out of some of the more tedious tasks such as hashing password values, enforcing password creation rules, and locking users out after too many failed login attempts.

Since most of us will be using this with the SqlMembershipProvider for storing the data in SQL Server, it should be noted that by default, this is setup in Visual Studio to work with SQL 2005 Express. For use in a production environment with a full version of SQL, you'll need to prep the database first. There's a utility called aspnet_regsql.exe included with Visual Studio that will do just that. It can be run from the command line or there's a nice GUI if you run it in Windows.

The presenter, Bill Evjen, is also a member of INETA.org, which is an organization of Microsoft user groups that can be a great asset to continue learning.

Session 2 - ASP.NET 2.0 Essentials for building Professional Websites
This was a decent if somewhat repetitive session, which seemed to just recap some best practices from earlier sessions such as:

  • Use master pages to control page templates.
  • Create user controls to reduce complex and duplicated code
  • Plan for localization when you build your site so it's easy to add in later if needed
  • Always provide custom error messages to your users. Use the global.asax to create a custom error handler to log errors and/or alert administrators.
  • Design and test a caching strategy to improve overall site efficiency.

Session 3 - The Atlas Application Framework
More good stuff on Microsoft's new AJAX-enabling framework for ASP.NET 2.0 by Dino Esposito. This session contained a lot more technical information that I don't have the space to recount here. I plan on trying out a lot of the Atlas demos in the coming weeks and will post some more in-depth info at that time. This is pretty bleeding-edge so I recommend that anyone who's interested simply download the Atlas framework and start playing with it.

Session 4 - Improving .NET Application Performance and Scalability
There is always a bottleneck. Find it. Remove it. Repeat.
That was the overall message of this last session of the conference. For any application that manages data and/or supports multiple users, tuning your application for performance should play an important role. Here are some good tips and tricks:

  • Minimize round trips for data. Write stored procedures that retrieve multiple recordsets rather than running multiple queries
  • Acquire late - release early - open your connection at the last possible moment and close it immediately after you're done. In most cases it's better to have multiple open/close statements than it is to open it once, do all your processing, and close it at the end. ALWAYS make sure to close your connections, SqlDataReaders, etc.
  • Put the processing closer to the resources it needs - If you need to sort or filter data, do it in SQL instead of returning a large recordset and doing it in code
  • Defrag and rebuild database indexes regularly
  • Use the StringBuilder class for string concatenations within loops

Parting Thoughts
I am exhausted. I've crammed more new information into my brain in the past four days than I have in the past four months. Although very tired, I'm also extremely encouraged. With tight budgets and tighter deadlines, often the emphasis is on getting the project done and not necessarily on getting the project done right. Conferences like this provide a great venue for developers to learn in-depth details about the new technologies being offered and how to effectively utilize them. I have several projects coming up this summer that should be able to take advantage of things like Atlas, localization, fragment caching, and web parts. The knowledge I learned this week should help prevent a lot of late nights in the office and allow me to catch up on something I've been missing for a while... sleep.

DevConnections - Day Three

I am not a morning person. I officially decided that these events start too early in the morning when I was stumbling around in the dark, half-asleep, tripped, fell into the wall, and nearly broke my nose. Yes, I am that awesome. Thankfully the rest of the day was not as awful as the beginning.

Session 1 - Accessing Data with the ASP.NET 2.0 Data Controls
This session was a decent introduction to the new data source controls in ASP.NET 2.0. Data source controls are non-UI helper controls that enable 2-way databinding with little or no code. I've already been using ASP.NET 2.0 for a couple months now so unfortunately there wasn't much new here. If you're new to ASP.NET you can view the slides from this session at www.deeptraining.com/litwin

One off-topic remark that speaker Paul Litwin made was about the new ways to encrypt your connection strings (and anything else you want) inside of the web.config file. This is a great habit to get into since it easily adds another layer of security to your application. Mr. Litwin has a great blog on the subject that will help.
Encrypting/Decrypting Web.config Sections

Session 2 - Localizing ASP.NET 2.0 Applications
Let's face it. Not everyone speaks English. Localization in ASP.NET 2.0 provides easy mechanisms for adding multi-language support to your projects. I have to say that I'm incredibly impressed by how easy this is. Using ASP.NET 2.0 localization allows you to maintain one core set of your website files and then use standard resource (.resx) files to implement however many languages you'd like. You can also setup a global resources folder for content that is repeated on multiple pages.

Most of the built in controls are localizable and there's even an asp:Localize control which can be used to wrap static content, making it localizable as well. Creating a method for the user to select a locale is simple and can be easily stored in a database for authenticated users or via a cookie using the Profile object for anonymous users. There's even a pretty easy way to add a custom caching parameter to vary by locale.

If you have any intention of creating a website in more than one language, the ASP.NET 2.0 localization features should not be overlooked.

Though not there at the time of this posting, speaker Dave Sussman has promised to post the slides and demos on his site at http://www.ipona.com/samples/

Session 3 - Maximizing ASP.NET Performance with Data Caching
ASP.NET 2.0 has made some major improvements to it's caching model which this session delved into. Caching can be set at the page level, selectively turned on and off for specific user controls, and the new data source controls have configurable parameters to apply caching to individual datasets. The web.config file now also supports caching profiles which can be configured and set for each page so different types of pages can have different caching durations and parameters.

Perhaps the most significant improvement though is the addition of sqlCacheDependency. Many sites pull content from databases, which is then cached. If the content in the database is updated, the page will still show the old data until the cache expires. SqlCacheDependency provides a mechanism for the database to notify the webserver of the change to automatically expire the cache. This can function both in SQL2000 and SQL2005, although 2005 enhances the process with what's called the Broker Service.
The code and slides for this session can be found at www.daveandal.com/download

Session 4 - SQL 2005 Indexing Strategies: Finding the Right Balance
I took a break from the ASP.NET 2.0 sessions and attended this one on SQL Server Indexing. I'm not a DBA but as a web developer I'm often stuck doing those tasks anyways. Indexing is a topic I'm planning to cover in more detail in a later blog and I gathered a lot of information here that will be helpful for that.

For now, here're a few quick notes from speaker Kimberly L. Tripp.
3 Things you need for doing database development:

  1. Know your data - Knowing exactly what data you're storing helps you design for performance
  2. Know your users - Knowing how people interact with the data helps you index for optimal performance
  3. Know what really goes on - Users often lie or are uniformed about how things actually work so profiling the user requests and server responses will help you figure out an efficient strategy

4 Steps for creating indexes:

  1. Create your clustered index
  2. Create indexes on primary key (PK) and unique keys (UK)
  3. Manually index foreign keys (FK) - This improves key relationship management and may improve join performance
  4. Manually create your extra indexes for AND, OR, JOIN, and aggregate queries

Full-text indexing has been significantly improved in SQL Server 2005 and catalog indexes now build 400% faster. The Index Tuning Wizard (ITW) has also been replaced by the newer Database Tuning Advisor (DTA), which possesses many new algorithms to help SQL optimize and run more efficient queries.

Session 5 - Building N-Tier ASP.NET 2.0 Applications
About half of this session was interesting. The other half admittedly went over my head. I'm most definitely not an application architect but, like not being a DBA, this responsibility often falls on my head. N-Tier is "a software architecture methodology that defines distinct physical or process boundaries between application modules." When you hear people talk about separating the data-access layer from the business logic from the presentation layer, their talking about N-Tier architecture.

One of the main benefits of this is flexibility and ability to re-use code. If you build your app on SQL server and then need to port it to Oracle, you can do so very easily by only modifying your data-access layer. There'd be no need to actually change any of your .aspx pages.

This concept is still pretty new to me. I'm lucky if I have time to actually build the project. Who has time to create an architecture?

That's all for today. 4 more sessions tomorrow and then it's back to the office.

DevConnections - Day Two

The morning started with keynotes touting many of the new and improved features of Visual Studio 2005. You can find some good demos, as well as a sneak-peak at the new ad campaign at www.400plusdifferences.com. After that it was off to the individual sessions...

Session 1 - Creating Dynamic Web Sites with ASP.NET 2.0 Web Parts
Web parts are a set of new controls in ASP.NET 2.0 that allow us to provide users with flexible display options and personalized content. The most common application of this interface would be for portal-type sites like MyYahoo and Google's personalized homepage but you can really leverage this technology for any kind of site.

The best part about web parts is that they work with existing ASP.NET controls and custom user controls with little or no effort. Just by dragging some controls onto the page you can quickly and easily give your users the ability to personalize the content. This could be a great feature for allowing your users to customize the homepage of any database-driven web application. By default the controls integrate seamlessly with Microsoft SQL server to persist data for authenticated users but that can also be modified to use any data store such as Oracle, MySQL, or XML.

Note: The drag and drop functionality to customize the display parts will only work in Internet Explorer at the moment but there are controls in the new Atlas framework that enable it for other browsers such as Firefox and Opera.

Session 2 - New Enhancements for Web Developers in Visual Studio 2005
This was an informative albeit sales-pitchy session about the improvements made to VS2005. My team has already been using VS2005 for a couple of months so a lot of the information I already had, but here's a quick breakdown of just a few of the cooler new features:

  • Built in development server. No need to have IIS installed
  • Better integration with SourceSafe for versioning and code control
  • WYSIWYG DataSet designer
  • Customizable tag formatting options
  • Better Intellisense
  • XHTML and 508/WCAG compliant code and built in validators

Another thing I should point out is that Microsoft has also released Visual Web Developer Express along with SQL Server 2005 Express. Both products are free to download and provide a great platform for developers to test-drive and learn ASP.NET 2.0 and the Visual Studio environment without having to plunk down hard-earned cash.

Lunch
I didn't plan on blogging about lunch but I had the pleasure of eating with Microsoft guru Joe Stagner who happens to be an exceptionally nice guy. We chatted a bit about Microsoft and general development stuff and he also pointed me to The Code Room, which is a "1/2 hour internet TV show that exposes technologists to the latest tools and technologies for tackling real-world software development issues". He wrote and produced an episode in Las Vegas last December that's worth checking out.

Session 3 - Using Visual Studio Team System to Build Enterprise ASP.NET Web Applications
Visual Studio Team System is a new version of VS that enables project management and collaboration functionality right within the developer environment. It also integrates directly with Excel, Project, and SharePoint to allow multiple developers and project managers to work together. While it seems useful for large teams working on an enterprise-sized project, I can't envision it being all that helpful for smaller web apps. They system is divided into parts for system architects, developers, and testers. Most of the developers I know (myself included) usually get stuck doing all three so this almost seems more bother than what it's worth.

One part I did find especially interesting however, was the testing features available for web applications. You're able to simulate any number of incrementally increasing users using multiple browsers to effectively stress test your applications before deployment.

Session 4 - An In-Depth Look at Building Enhanced Web Apps Using Atlas
By far the biggest draw so far, the Atlas session was packed with people standing and sitting in the aisles. For good reason it would appear. Atlas seems to be the most interesting surprise in Microsoft's bag of tricks.

Atlas is a cross-browser JavaScript library and server-side assembly that provides AJAX functionality on top of ASP.NET 2.0. The most impressive part about it is that it enables AJAX-style partial-page rendering without a lot of work and without having to write any complex JavaScript. The coolest part for me was the ability to extend existing controls within the framework such as adding drag and drop functionality or auto-complete for textbox controls.

Session 5 - Cool Tips & Tricks in ASP.NET 2.0
The day concluded with a session by keynote speaker Scott Guthrie who is not only brilliant but also a great presenter. It was designed to provide 10 tips and tricks to help increase overall productivity and it was exceptionally beneficial. I won't bother to recap the tips and tricks Mr. Guthrie provided since he's made them available on his blog. I highly recommend downloading this session.
ASP.NET Connections Tips and Tricks Slides+Demos Posted

DevConnections - Day One

Right now I'm down in beautiful Orlando, FL for the 2006 Microsoft DevConnections conference that my company was gracious enough to send me to. Today was day one and I just returned from the reception and keynote speeches by Scott Guthrie and Matt Nunn. Both speakers were excellent and I'm looking forward to the sessions tomorrow.

There's a ton of stuff going on during the next three days but I'm going to concentrate on the ASP.NET track. It looks like one of the more interesting topics is going to be "ATLAS", Microsoft's new framework for implementing AJAX functionality in ASP.NET. Mr. Guthrie did a brief demo of it during the keynote and it looks very impressive. With just a few lines of code, he took a DataGrid with paging, sorting, edit, and deleting, and made the whole thing AJAX-enabled. It looks both easy and powerful, and best of all it's free. You can download the Atlas framework from the asp.net site and try it out.

One of the more interesting things I found out was that the popular social networking site MySpace.com is running on ASP.NET 2.0. MySpace ranks as the #2 most popular site on the Internet (Yahoo! holds #1) with 1.5 billion page views per day. That's some serious traffic. Later this month they plan to role out a new profile personalization engine using Atlas so that'll be something to look for.
More info on how MySpace takes advantage of Microsoft technology.

There're conference sessions and events from 7AM until 9PM tomorrow so I'll hope to have some more good info to report then.

MSDN Webcasts - Good Info / Free Stuff

One of the most difficult parts of our job as web developers is keeping up on the latest technologies and trends in the field. Microsoft, to their credit, plays an active role in helping developers learn to use their new products and services. This week I've been watching several different webcasts on ASP.NET 2.0, Visual Studio 2005, and Atlas. They're very informative and best of all free.

For developers who can find the time to watch 3 of these webcasts, Microsoft is offering a "Visual Studio 2005 Discovery Pack" which includes:

  • Microsoft® Visual Studio® 2005 Professional Edition 90-day DVD trial
  • Microsoft Visual Basic® 2005 Jumpstart book from O'Reilly
  • Discount voucher for Visual Studio 2005 Professional Edition with MSDN® Professional Subscription
  • Microsoft Developer Security Resource Kit
  • Discount voucher for Microsoft Certified Professional Exam
  • Free 30-day hosting account

It's definitley worth the time and free stuff is always a bonus so check out the Visual Studio 2005 - The Difference is Obvious webcast series.

My day with Microsoft

I spent the majority of my day at the Microsoft launch event for SQL Server 2005, Visual Studio 2005, and BizTalk Server 2006. Microsoft does events like this periodically across the country and they're often free (as this one was) or relatively inexpensive. They provide great insight into some of their new products and services and they often give away software, books, magazines, etc. At the very least it's free food and a day away from the office so I recommend them to anyone in the field.

This particular conference was pretty good, although I don't use BizTalk and I'll admit that some of the SQL stuff went over my head. I, like most of my readers, user SQL Server for small to medium web applications like content management systems, not things like massive enterprise-level transaction based banking systems.

I'd already been playing with Visual Studio 2005 and ASP.NET 2.0 so I was mainly interested in the SQL Server 2005 info. Some of the new features were pretty interesting so here's a few of my random notes on that topic:

  • SQL 2005 now has an XML data type which you can use to store XML data. You can also store a schema for the data to validate against and use XQuery to query it within a SQL statement
  • End user ad-hoc reporting is now built into the Reporting Services allowing users to create reports on the fly
  • Improved error handling features have been added to T-SQL in the form of Try/Catch blocks
  • SQL 2005 now has built in data encryption functions using both symmetric and asymmetric keys
  • SQL-CLR allows you to write things like Stored Procedures, Functions, and Triggers in VB.NET or C#
  • New LOB support with varchar(MAX) and varbinary(MAX) allowing you to store large amounts of data without using text and image fields.
  • CacheSync - allows data from the database to be cached by IIS. When the data is updated, SQL Sever will automatically let IIS know to expire the cache.

One last thing, not SQL related, is that the new Team Foundation Server allows developers to work together and integrates new source code control functionality into Visual Studio as an alternative to SourceSafe. SourceSafe (even the new 2005 version) isn't exactly everyone's favorite application so let's hope this will be better.

That's it for now. I want to give a quick thank you to everyone who reads this blog for the positive feedback I've received so far. I love comments so keep posting them and/or send any ideas, stories, etc. to jay@codescene.com.

Party like it's 1/1/1900

(or how to insert null values into SQL using ASP.NET)
I've built several online applications using Microsoft SQL Server as the backend database and one thing that's always given me trouble was inserting dates, or more specifically NOT inserting dates.
Users can enter a date or use a calendar control to select one and, assuming it's valid, it goes into the database with no problems. But what happens when the user leaves the date field blank? If SQL is expecting a date, and you pass it a null value instead, it ends up in the database as the SQL default date of 1/1/1900 when most often you just want it left blank.

So how do you insert a blank value into the database? Here's an easy trick using VB.NET (assuming txtDate is an asp:TextBox)

<%@ import namespace="System.Data.SqlTypes" %>

Dim nulldate As SqlDateTime
nulldate = SqlDateTime.Null

If (txtDate.Text = String.Empty) Then
    cmd.Parameters("@Date").Value = nulldate
Else
    cmd.Parameters("@Date").Value = txtDate.Text
End If

Book Review: ASP.NET 2.0: A Developer’s Notebook by Wei-Meng Lee

ASP.NET 2.0: A Developer's Notebook, part of a new series by O'Reilly Media, takes a radically different approach to code-oriented textbooks, and it's about time. O'Reilly has done something wonderful in realizing that most developers simply don't have the time to read through 1200-page books trying to learn every little detail about a subject.

Instead, we usually only have a matter of days (hours if we're really unlucky) to learn enough about the language we're using to make the project work. That's what this book is about... getting the job done. This books aims to be the brain of a great developer poured onto paper. You won't find useless chapters on theory or elaborate references of class hierarchies and object properties. What you will find is page after page of hands-on code examples that you can actually use.

Topics covered include:

  • Master pages, themes, and skins for easily creating a consistent look throughout your site
  • The Web Parts Framework (WPF) for building portal applications
  • Security and membership controls for managing user authentication
  • Data access via new data source controls and the GridView component
  • Performance tuning your site by pre-compiling and fragment caching.

ASP.NET 2.0: A Developer's Notebook is a book for developer's who would rather learn by coding instead of just reading. This is the perfect book for developers familiar with ASP.NET 1.x who're looking to make the jump to ASP.NET 2.0 and Visual Studio 2005 without wasting every second of their free time. It throws you into the code immediately, allowing you to learn by example. The code samples are all easy to follow and you can re-use them in your own applications. This is a must-have for anyone trying to learn ASP.NET 2.0.