Wednesday, March 08, 2006

I'm an uncle (again)

My sister had her second child today (a boy)!  His name is Preston.  I’m very proud and I can’t wait to meet him!

Photo 17

Podcast - Ben Day on NHibernate

Benjamin Day spoke at Visual Studio live this year and was interviewed by Channel 9.  He talks about NHibernate.  If you don’t know what NHibernate is, it’s an object-relational mapper aiming to reduce/eliminate common data access code.  It’s based on the mature Hibernate for Java, and has growing community support.

Anyway, Ben Day and I used to shoot ideas back and forth and talk about NHibernate patterns and limitations.  He mentions me in the podcast (!), which you can download here.

Thanks Ben!

Developing for a Domain Environment

Internal applications commonly utilize Active Directory to manage their user-base.  With this approach organizations can define the users and roles in one central location, and have that information available to many applications.

For intranet websites, this is accomplished by using Integrated Windows Authentication.  But what happens when you are developing on a machine that does not have the same accounts as the target environment?  Case in point:  say you have some Active Directory domain groups that define who the “readers” of an appliciation are and who the “editors” are.  The simple solution is to make these groups configurable through the web.config, and you can have something like this for development:

<add key=”adminRole” value=”Administrators” />
and something like this for production:
<add key=”adminRole” value=”DOMAIN\ApplicationAdmins” />

This gives us the benefit of using a local machine account for debugging the different roles, and allows for Integrated Windows Authentication to work properly.

Here’s another concern.  What if your code accesses a secure resource like a database or web service that requires valid Windows credentials and authorization?  A test database can easily be configured to accept SQL Authentication provided via connection string, but a Web Service that requires integrated Windows authentication?  Would you really want to mock a complex external dependency like this (Especially if it is a read-only dependency) ??  If you do you end up spending a large portion of your time just setting up the environment to develop in. 

I was dealing with a scenario just like this and I wanted to do use the web.config’s impersonate=”true” feature where I can supply a username & password to run as (You can even configure it to encrypt this data and store it in the registry using aspnet_setreg.exe… see here).  The problem here is that if I give it a valid domain account to impersonate, my local machine cannot authenticate me unless I join the computer to a domain.  For a lot of scenarios this is way too much to ask, and may not even be an option.

I could end up just constructing a NetworkCredentials object with the credentials I need to access the secure web service, but I don’t like that approach either.  It requires me to specify an account in plain text (either in code or in web.config… both of which are bad ideas.

Any thoughts on this?

Thursday, March 02, 2006

Webhost Hiatus

Well my webhost crashed and I lost a month of posts.  I’m trying to see if I can find a more recent backup, but for now this will have to do.

I moved over to webhost4life.  They have pretty good hosting for $10/month for:

  • asp.net 2.0
  • sql server 2000
  • sql server 2005
  • mail

The only downside is that you have to pay $15/year for each domain that points to a folder other than your root.  So if you have 2 sites, you’ll have to put them in their own subdirectory, and pay a little extra to get the domain to point there.

Still not a bad deal for 2 sites, $150 for a year, including mail.

Sharepoint Portal Server Installation

I was installing Sharepoint Portal Server 2003 at a client site this week.  During and after the install we were getting very strange errors, eventually leaving the site useless until we could figure them out.  Installing WSS Service Pack 2 and SPS Service Pack 2 helped get through the installation, but even after the site was completely installed, we still received lots of errors.

It turns out that IIS didn't have script maps for ASP.NET 1.1, so only 2.0 showed up in the list.  Though the updates are supposed to work with 2.0, my experience tells me otherwise.  Sharepoint Portal Server 2003 *definitely* has issues if you run it in 2.0.  To add the option for 1.1 in IIS, you can run:
c:\windows\Microsoft .NET\Framework\v1.1433\aspnet_regiis -i
This will reinstall the script maps for that version into IIS.  I changed the SPS site to use 1.1,  but I still received errors. 

A reinstall put the site back on 2.0, which was quite odd...  I got the same errors as before.  Finally, to fix it I disabled 2.0 in IIS 6.0's Web Service Extensions section.  Then I reinstalled SPS, which was then forced to use 1.1.  All was well with the world after that...
Sunday, January 08, 2006

SqlExpress connection under Remote Desktop

While developing a small website this week I ran across an unusual error. 

When on my lapop, I generally remote into my desktop PC because it has Visual Studio and all the tools I need.

I decided to use a SqlExpress file as the database, since there won’t be much data for the application.  This worked for about 2 weeks until I got this error upon opening a connection:

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

This error has to do with the fact that I am using remote desktop to develop.  When I access a file-based sql express database, the data is actually copied locally, which is why it takes so long to start up. 

Kevin Jones says:

SQLExpress creates a directory per user in "c:\Documents and Settings\[user]\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" that it uses to store information. Deleting this directory has fixed both of my problems.

I’ll update this with my results.

Update:  It worked!  How weird.  This fix definitely looks temporary but it’s working for me so far.

Thursday, December 08, 2005

I'm all banged up!

On Thursday, I was involved in a serious car accident.  I hit a dump truck head on.

My car was mangled beyond belief, both airbags deployed, and I was in bad shape.  My right leg was obviously broken; it looked like a pillow doubled-over on itself. (Ouch!)  My left arm was also obviously broken.

Paramedics arrived quickly, they pulled me out of my car (quite painfully) and I was laid on a stretcher.  I heard someone say “be still, this might hurt,” and then followed the most painful thing I have ever encountered.  He pulled my leg to re-set my femur.  My leg popped loudly 3 times while I begged him to stop.

I was put on a helicopter and flown to the hospital.

Later that evening I had surgery on my arm and leg.  On my right femur, they inserted a titanium rod to fuse the bones back together.  For my left radius, they inserted a few pins to fasten a loose piece of bone.

I stayed in the hospital until Tuesday evening.  I am home now, basically immobile for I assume quite a while.

I guess I should consider myself lucky.  I am thankful for all my friends and family who showed support and came to visit or called during this tragedy.

Tuesday, November 29, 2005

Adding Javascript to ANY CommandField control

In the previous post, I mentioned how annoying it is to have to treat an ImageButton separate from a Button and separate from a LinkButton when they are all essentially the same thing.

The answer here lies in the IButtonControl interface, (whose name strongly suggests that it should be a direct parent, not an interface, but oh well)…

Here’s how you’d add javascript and tool tips to those CommandField button controls, without having to write specific versions for all three:

    1 protected void gvCrews_RowDataBound(object sender, GridViewRowEventArgs e)

    2         {

    3             //grab last column (the command column)

    4             int cmdCol = gvCrews.Columns.Count - 1;

    5             foreach (Control ctrl in e.Row.Cells[cmdCol].Controls)

    6             {           

    7                

    8                 IButtonControl btn = ctrl as IButtonControl;

    9 

   10                 if (btn != null)

   11                 {           

   12 

   13                     if (btn.CommandName == "Delete")

   14                     {

   15                         ((WebControl)ctrl).Attributes.Add("onClick", "return confirm('Are you sure you want to delete the crew and its ENTIRE history?  This cannot be undone...');");

   16                         ((WebControl)ctrl).ToolTip = "Click here to delete";

   17                     }

   18                     else if (btn.CommandName == "Edit")

   19                     {

   20                         ((WebControl)ctrl).ToolTip = "Click here to edit";

   21                     }

   22                 }           

   23             }   

   24         }

 This way I can still change the look & feel of the GridView CommandField and I don’t have to recompile to support it.  Unfortunately the IButtonInterface doesn’t allow for javascript attributes or tooltips, so I have to cast the control as a WebControl to add those in.  Setting CausesValidation=true still causes an exception for the ImageButton though, so I haven’t figured out a way around this yet.

Now playing: Nine Inch Nails - The Hand That Feeds

GridView CommandField Validation woes

Today I was working with a simple form, a single textbox at the top with a button for adding items, and a gridview below for editing/deleting.

With 2.0’s validation groups, we can have validation on the “Add” form by setting validationgroup=’AddGroup’ and we can have our CommandField column of the GridView have validationGroup=’editDelete’.  Ideally this will separate the 2 actions into their own validation groups and they won’t bother each other.

Well, if you are using ImageButtons instead of LinkButtons for your CommandField, there is a slight problem.  The ImageButton actually gets instantiated as DataControlImageButton, which cannot use the CausesValidation property.  Here’s what happens:

DumbException

Now why does this generate a NotSupportedException?  This is a perfectly valid scenario for validation?  In this particular case I do not care about the edit/delete validation, but I do care about the Add validation. 

If I change this scenario to work with LinkButton or just Plain Button, it all works out fine.

I have another rant regarding this same concept.  The above screenclip is showing the RowDataBound event handler, and I am looping through the controls in the last column of the GridView.  Now the last column is going to be the CommandField, so I know that there will be some commandcontrols in there.  At this point I should not care whether it is a Button, an LinkButton, or an ImageButton because I will be treating them all the same:  I will compare their CommandName properties to see what they are doing.  So why can’t I just cast the control as Button?  Well ImageButton doesn’t even derive from Button!  I am sure there are reasons for that, but I don’t see them.  This means I have to recompile my code if some UI guy decides they want a link instead of an image for their Edit command.  Dumb, I say.  An ImageButton, by nature, is a button, not an image.  It’s behavior is a button.  The way we treat it as developers is just like a button.  It’s view or representation however is an Image, just like a standard button has a raised, rounded rectange as its view.  Someone please explain to me why I’m wrong….

Now playing: Jimi Hendrix - Red House

Sunday, November 27, 2005

Engaged!

I proposed to my girlfriend, Silvia, on Thanksgiving in front of her entire family.  She said yes!  It was quite an occasion.  We aren’t yet sure when the date will be.

I’ll post some pictures of our trip to upstate New York soon, one of them has me on one knee .

Tuesday, November 15, 2005

vs2005 beta 2

Visual Studio 2005 Beta 2 is dying on me…  I wonder if it knows that I am about to replace it with the RTM version.

Any time I Rebuild All or run my app and play with it for 1 or 2 minutes Visual Studio just exits, no error message, no restart, nothing.  Makes it quite hard to develop, donchathink?

I am kind of reluctant to update to RTM too soon since we have apps in development under beta 2.

 

Now playing: Dave Matthews Band - All Along the Watchtower

Wednesday, November 09, 2005

A cool free online service.

I just thought I’d plug a cool website I found today.  It’s called Side Job Track and it’s pretty sweet.  It allows you to track side projects for just about any type of project.  Includes free invoicing, simple reports, and a client list.

This is perfect for my few-and-far-between computer service/networking jobs I get from time to time. 

Check it out, it’s totally free.

Now playing: Nirvana - The Man Who Sold The World

Remortgages - Loans - Credit Counseling - Credit Card Consolidation