OdeToCode IC Logo

Going Independent

Monday, August 16, 2004 by otcnews
If you want some insight into the minds of two talented developers and authors, read James Avery's post and Scott Mitchell's post about their thoughts on becoming independent software contractors.

Resolving DateTime FormatExceptions

Sunday, August 15, 2004 by otcnews
Alan Dean shows how to use SQL Server's CONVERT function to stop exceptions when using the DateTime Parse function on a stored procedure resultset.

Lost Data With a StreamWriter

Sunday, August 15, 2004 by otcnews
Microsof't BCL team gives an in-depth description on the importance of closing a StreamReader object.

Visual Studio 2005 Notes

Saturday, August 14, 2004 by scott
 It’s experimentation day.

I was looking at some web forms with Trace enabled in ASP.NET 2.0, looked at the ViewState size, and remembered reading about some view state enhancements in 2.0. So I did a little experiment.

In ASP.NET 1.1 I rendered ‘SELECT * FROM pubs..employee’ in a DataGrid control using all the default settings (auto-generated columns, ViewState enabled). The resulting page used 26,241 bytes.

In ASP.NET 2.0 I rendered ‘SELECT * FROM pub..employee’ in a DataGrid control, again using all the defaults. The resulting page used 16,089 bytes. A difference of 10,152 bytes, which is quite a bit if you insist on enabling ViewState on a DataGrid. The same experiment using the new GridView control, with sorting enabled, ran 17,996 bytes.

For anyone who has not seen the GridView in action, Dino Espisito has an article: Move Over DataGrid, There's a New Grid in Town!


I noticed in the trace there is a new PreInit event in the page life cycle. This makes me wonder if we might need a PrePreInit event in ASP.NET 3.0? Perhaps a BeforePreInit?  

It turns out PreInit is the event to grab in order to dynamically change the personalization, theme, or master page settings (it was also time to get in touch with my kindler, gentler, VB side, but don’t tell anyone):

Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

    MasterPageFile = "~/FunkyDoodleLayout.master"

End Sub

Setting the MasterPageFile property after the PreInit event only throws an exception. Paul Wilson has a good introduction to the Master Page feature: Standardize Your Site Fast With Master Pages.


Somehow, in the middle of this, I began surfing and read about Boston’s Great Molasses Flood of 1919. I’ve never heard of this and first thought it was an urban myth, but it’s not. A 30 foot high wall of molasses moving at 35 miles per hour.  


The code expansion in C# is quite good. I type the ‘using’ keyword, hit the TAB key, and the IDE inserts a code block for me:

using (resource)
{
 
}

The word resource appears in yellow and is selected, so I just need to type in the expression. If you expand a for statement, then the initializer is highlighted. As soon as you change the variable name in the initializer, the IDE changes the variable name in the expression and iterator to match, saving quite a few keystrokes.

What is interesting is the C# code snippets center around simple block statements (lock, using, for, do). The VB snippets seem to include entire algorithms. You choose to “Insert Snippet…”, then chose “Processing Drives, Folders, and Files”, then “Parse Column Data In a Text File”, and the IDE spits out the following code, where the file name and delimiters array are replaceable by tabbing through the snippet and typing (this is hard to describe, you just have to try it):

' This example parses a file with this structure.
' Line1Column1, Line1Column2, Line1Column3
' Line2Column1, Line2Column2, Line2Column3
' Line3Column1, Line3Column2, Line3Column3
' Line4Column1, Line4Column2, Line4Column3

Dim parser As TextFieldParser
parser = My.Computer.FileSystem.OpenTextFieldParser("C:\TextFile.txt")
parser.Delimiters = New String() {","}
Dim fields() As String
While Not parser.EndOfData
    Try
        ' ReadFields reads one line of data from the file.
        ' Array 'fields' contains one string element for each column.
        fields = parser.ReadFields
    Catch ex As MalformedLineException
        MsgBox("Error on line: " & ex.LineNumber)
        Throw ex
    End Try
End While
parser.Close()

As I’ve said before, someday I’m going to come home and find my cat has written a Tetris clone by sleeping on my keyboard. In VB of course.

I Can't Take The Heat

Thursday, August 12, 2004 by scott
The air conditioner is broken at work and I am now sitting in the world’s only sauna that requires business casual dress. Like a fine Pinot Grigio, I must be properly chilled before I can reach my full potential. It’s too hot here to debug software, so I’m going to blog.

I work in a government technology “incubator” building, meaning there are a dozen startup companies around here and we share a common copier room, common break room, and common conference rooms. The key word here is ‘government’. I have complete faith the county maintenance people feel my discomfort and will rush to fix the air conditioning problems just in time for the first major snowfall of the year.

In other news, I’ve been under a lot of peer pressure lately. Test driven development is a great way to write quality code, but sometimes good old fashioned peer pressure works just as well. Why just recently I opened the latest build notes to look at the list of file diffs. Imagine my surprise when I see:

File Check-in Date Version Check-in By Comment
VisitSearch.ascx.cs 8/8/2004 11:42:36 AM 2 Plall Fix Scott’s sloppy code.
Ouch. Now I have another excuse not to write code. Not only is this room so hot I feel I should be wearing sunscreen lotion, but if I slip up in these conditions my work is subject to public humiliation. Time to find cooler air….

Reporting Services Security

Wednesday, August 11, 2004 by scott

For anyone facing authentication or authorization errors in a Reporting Services environment, or just looking for some introductory material, I've posted two new articles to OdeToCode:

Introduction To Role-Based Security In SQL Server Reporting Services

Authentication, Role-based Security, and Reporting Services Web Services

If you give them a read, please let me know if you think they are easy to understand, and please let me know if they contain any errors.

Internet Explorer in Windows XP SP2

Wednesday, August 11, 2004 by otcnews
Tony Chor provides a high level description of architectural and user experienece changes made to Internet Explorer in XP SP2.