logo
  • Jobs
  • About Me
  • Contact
  • Home

Archive for June, 2005

Add Application Extension in IIS

Earlier tonight, I was trying to setup a new file extension for a web application using IIS. The idea was simple enough. Default Website | Home Directory | Configuration | Application Configuration.

I tried clicking the Add button to add an extension, but when I did the OK button was always disabled. No matter what, I could not get it to enable.

This is one of the sillier workarounds I’ve seen in a while. After selecting the executable, you need to click on the textbox itself and the path will fully expand, enabling the OK button so you can save the mapping.

No Comments

Steve Jobs’s Commencement Address at Stanford

Steve Jobs’s 2005 commencement address at Standford is a message of hope. The address is outstanding and should be read by everyone.

“You’ve got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.”

No Comments

Recruiting Advice

As proven by this advertisement, it is all about *who* you hire…

1 Comment

Custom Configuration Sections in Beta 2

I spent a little time this afternoon delving into Whidbey Beta 2, after finally surfacing from other priorities at work.

One of the things that I’ve been really interested in is the Provider pattern, and so I decided to start understanding a little more how this pattern works in Whidbey. I’ve used this pattern quite a bit in .NET 1.1, however, the nice thing about 2.0 is that a lot of the base classes are already there for you.

As I was investigating further, there was one thing that really caught my eye. This was the new Configuration mechanism which you can use to create your own custom configuration sections. You know have the option to do this all declaratively (by deriving ConfigurationSection), instead of manually parsing the XML like you did with 1.1.

As I was looking through some of the pre-built ConfigurationSections, in my mind, there was one that was conspicuously missing considering the emphasis of the Provider pattern in .NET 2.0 and that was a Provider section.

What I hoped for was a class that would allow me to declare a section that looked something like this:

<sectionName defaultProvider="">
    <providers>
        <add name=""
            type="" />
    </providers>
</sectionName>

Unfortunately, I did not find one, so I wrote one out. This also helped me to understand the new configuration mechanism, and saves me from having to re-implement the same logic for any other providers I may author in the future.

Take this code:

public class ProviderSection : ConfigurationSection
{
    private readonly ConfigurationProperty defaultProvider = new ConfigurationProperty("defaultProvider", typeof(string), null);
    private readonly ConfigurationProperty providers = new ConfigurationProperty("providers", typeof(ProviderSettingsCollection), null);
    private ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
 
    public ProviderSection()
    {
        properties.Add(providers);
        properties.Add(defaultProvider);
    }
 
    [StringValidator(MinLength = 1)]
    [ConfigurationProperty("defaultProvider")]
    public string DefaultProvider
    {
        get { return (string)base[defaultProvider]; }
        set { base[defaultProvider] = value; }
    }
 
    [ConfigurationProperty("providers")]
    public ProviderSettingsCollection Providers
    {
        get { return (ProviderSettingsCollection)base[providers]; }
    }
 
    protected override ConfigurationPropertyCollection Properties
    {
        get { return properties; }
    }
}

Immediately, you should notice the two attributes on the DefaultProvider property. The ConfigurationProperty attribute denotes which attribute should be used for loading the property, and the StringValidator attribute insures that the attribute is at least one character long. How cool is this? To write something like this in 1.1 would have taken easily 3 times as much code.

No Comments

No more stored procedures…YAY!

During a recent upgrade to an application Ive been working, all but one of the stored procedures was removed.

What?!?! Indeed, data access can happen without stored procedures, and as referenced in some other weblog posts this may be very advantageous. Go ahead and read this post (stored procedures are bad, m’kay?) now… I’ll wait.

In the case of this particular application, there was always an issue about keeping three different projects in sync (the DAL, the database project, and the installer project).

Any time that I needed to make a change to retrieve additional data from a table in the application’s database, I had to make changes to three projects. First off, I had to update the database project to modify the stored procedure. Once that modification was done, I was able to modify the Data Access Layer to use the new field. Finally, when everything was done, I needed to remember to update the installer project so that the scripts that create and update the database have the correct stored procedures.

Now, as you can see this can cause quite a bit of headache and an update process that can be very prone to error. The way that I found to get around this is to move all but the most complex stored procedures (the ones that were actually performing real work) into the DAL directly.

What this means is that instead of having a stored procedure that does ‘SELECT * FROM Users’, I send that command directly to the SQL database using the SqlCommand object in the .NET framework. The technique is identical to what is used to execute the stored procedures.

One thing that I hear quite a bit is that you open yourself up to Sql injection attacks when using dynamic sql, instead of stored procedures, because you can not use parameters. This is completely wrong. Let me show an small working example:

SqlCommand cmd = new SqlCommand("select * from users where UserName = @UserName");
cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = someUserNameVariable;

You see here that you have exactly the same parameter semantics as you do using stored procedures. These semantics allow you to pass values into the parameter object where they will be scrubbed to make sure that no sql injection attacks can take place.

Using dynamic sql in the data access layer, if I want to update the columns that are pulled back, I no longer have to modify a stored procedure in the database project. Also, I dont have to modify the installer project, because all of my sql is right where it belongs… in the data access layer.

3 Comments

Official VS.NET 2005 Launch Date

As part of the keynote address, Paul Flessner, senior vice president of Server Applications at Microsoft, showed the company’s continued momentum in preparation for the launch of SQL Server™ 2005, Visual Studio® 2005 and BizTalk® Server 2006, and announced that these products will be formally launched during the week of Nov. 7.

via microsoft.com

No Comments

Disabling the system beep

This came through an an email thread this afternoon and I thought Id share this with the rest of you.

Under Virtual Server, there are a lot of annoying beeps that occur as some sounds appear to beep (since there is no sound support under Virtual Server). Turning it off is fairly straight-forward if this beep drives you bonkers (as it does me).

  1. Open up Device Manager on the host machine (the one that you are using to control the virtual server).
  2. From the View menu, select ‘Show hidden devices’.
  3. Expand ‘Non-Plug and Play Drivers’.
  4. Right-click ‘Beep’ and select ‘Properties’.
  5. Select the ‘Drivers’ tab.
  6. Click ‘Stop’.

You can also change the startup type to ‘Disabled’, so that the beep service never starts.

This is a great tip… Thanks, Jay!

3 Comments
flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010