Home for the holidays, can you look at my laptop? (Part 2 – the demise of a video card and the MBR)

My brother lugged two kids and two laptops from Phoenix.  At various times through the day today, I’ve been surrounded by all four of them.

This particular episode involves a Dell Inspiron 600m.  I’ve never seen a display look like this.  Either the LCD is totally shot, or the video card is shot.  After some diagnostics with Dell tech support, it’s the video card.  Which means a new motherboard.

During the diagnosis, the laptop ceases to boot past the Windows screen, repeatedly bringing up a BSOD about the master partition.  Pulling out my trusty new Slax bootable USB key, I can access the data on the HDD, so the drive controller and drive are OK.  As long as the drive is OK, the controller doesn’t matter—we’ll have a new one soon anyway, with the rest of the motherboard.

So, it’s off to eBay to locate a new motherboard, and then a Windows restore once he ships me the CDs.  Looks like he’s going home with 2 kids and 1 laptop.

DotNetKicks Image

Home for the holidays, can you look at my laptop? (Part 1 – Linux saves the day)

One of the great joys a family has when a member works in IT is onsite technical support when we all get together.

The Victim

Part 1 is pop’s laptop, which picked up a nasty malware bug somewhere.  Probably one of the hundreds of funny videos he gets sent by all his buddies.  Despite AVG and Windows Defender, something got in there and screwed up the userinit.exe.  We could get to the welcome screen, but as soon as you clicked the username, you’d be immediately logged out.

The Scan

I found a great list of free bootable rescue CDs, and downloaded and ran the offering from f-secure.  The f-secure disk boots into a network enabled Knoppix environment, and you can grab the latest definitions file via network or onto a USB key, which I did and the software located automatically.

The scan found and and quarantined one infected file, and a couple previous infected versions in the system restore archives.  It was the userinit.exe, so now the task becomes replacing it.

The (failed) System Recovery

HP/Compaq doesn’t ship recovery disks anymore.  Instead, the recovery is located on a secure partition you boot into.  This is important to know, because if I had known this at first, pop’s laptop would have been fixed a week ago when he UPS’d it to me.  After running the online recovery, I was still unable to log in to Windows.  This meant we had to use the destructive restore.

The Data Recovery – Linux to the Rescue 

To prevent losing data, I had to boot the system and copy it off.  I first tried a Windows LiveCD made with BartPE, but my laptop has an IDE drive, and pop’s has SATA, so there were no drivers for his HDD.  Plan B was to boot into Linux.

The first Linux attempt was an Ubuntu 8.10 LiveCD.  Ubuntu must not support SATA on its LiveCD, because it couldn’t mount the drive.

Next attempt was PC Linux OS, which is my favorite distro running under Parallels.  I made a bootable thumb drive following the instructions at PenDriveLinux.  We booted and mounted the SATA drive, but by default the thumb drive is not writeable, and I couldn’t enable writing to the drive.

My last attempt was to use Slax.  I made a bootable USB key with Slax.  Slax is very lightweight, and has an attractive KDE shell, easy networking (using WEP), and a good set of standard  utilities for burning CDs and DVDs.  Some of the critical data I copied to the thumb drive, and the rest (iTunes, grandbaby photos) had to go on a DVD.

The Destructive Restore

After recovering the data, I had one last-ditch idea, to replace the userinit.exe on pop’s machine with the one from my machine.  No dice.  Don’t know why, but didn’t work.

So, I booted into the recovery mode, and did the destructive restore.  Success!  After a small amount of configuration, and reinstalling his software (thankfully he’s un-savvy enough to only have a couple programs), he was up and running.  And now it’s time to finish changing all the passwords.

Moral of the story

HP/Compaq’s onboard restore partition is handy and well designed, but the simple non-destructive recovery may not be enough after a malware infection.  When you need to recover data, Slax is a lifesaver.

DotNetKicks Image

Just Arrived: Crystal Reports Encyclopedia Vol 2

Congrats to Brian Bischof for publishing Crystal Reports Encyclopedia for .NET 2005 and 2008, and the redesign of the companion site at http://www.crystalreportsbook.com/.

In the past, I can’t say enough how helpful Brian’s books have been.  These are the manuals Crystal Seagate Business Objects SAP should send out with the software.  Brian’s books are very readable, very easy to follow, and have examples in both C# and VB.NET.

If you’re doing any work at all with Crystal Reports, you owe it to yourself to get the corresponding book and get to work.

DotNetKicks Image

How to create a CSV or delimited list with an ID field in t-sql

A question in the asp.net forums wanted to return the following output:


ticket_id          assigned_to
1                       bsmith csmith dsmith


but was getting


ticket_id     assigned_to
1                  bsmith
1                  csmith
1                  dsmith


Since T-SQL (an query languages in general) lacks a lot of the array and concatenation features we take for granted in programming languages, you need to do a little trickery to make this work.  There are probably several ways to pull this off, but here’s what I did.


My first thought was the great creating a CSV list in SQL using coalesce example.  But, the tricky part here is that he wanted the ID of the ticket along with the list of the users assigned to the ticket, and you can’t assign a value and retrieve data in the same statement.  So that means we have to use some sort of updateable array (which is usually a table variable or temp table in T-SQL) and a loop (I’m not partial to cursors, so I used a WHILE loop).


The original question had two tables joined together, so I tried to mimic the structure for my solution.  The tables I used looked like this:



work_tickets
ticket_id     assigned_to_id
1                 1
1                 2
1                 3



work_tickets_assignment
user_id     user_name
1              bsmith
2              csmith
3              dsmith


And here’s the SQL I ended up with.



— table variable to hold intermediate results
declare @assignments table(ticket_id int, assigned_to varchar(100))


–couple of variables used in the loop
declare @assigned_to varchar(100),
    @ticket_id int


— populate the table var with a list of all tickets
— modify sql to suit your needs
insert into @assignments(ticket_id)
select distinct ticket_id from work_tickets
order by ticket_id


— get the first ticket w/o any assignment information
select top 1 @ticket_id = ticket_id
from @assignments
where assigned_to is null


— if anything was retrieved in the previous query
— when we reach the end of the table, @@rowcount=0 and loop will end
while @@rowcount >0
begin


    — get all users assigned to the work ticket and join them into a space
    — delimited list
    — modify join and where to suit your schema
    select @assigned_to = coalesce(@assigned_to + ‘ ‘,”) + convert(varchar(6),user_name)
    from work_tickets_assignment as a
    inner join work_tickets as t on a.user_id = t.assigned_to_id
    where t.ticket_id = @ticket_id


    — add the user list into the table var
    update @assignments
    set assigned_to = @assigned_to
    where ticket_id = @ticket_id


    — important!! clear the list
    set @assigned_to = ”


    — get the next ticket w/o assignment info
    — loop will end if we’re done
    — this query should match the one outside the loop
    select top 1 @ticket_id = ticket_id
    from @assignments
    where assigned_to is null


end


— return the contents of the table var
select * from @assignments









This have me the exact result the questioner wanted.  It’s not the most scalable piece of code, but in a test on some other data I have, I was able to update over 800+ unique “tickets” with over 2000 “users” in under 4 seconds.  Like I said, not the most scalable, but it will get the job done for smaller data sets.

DevTeach wrap-up

I can’t believe I’ve been back for a week, this week has been a blur.

I have to say thank you to the Montreal .NET Community, JS Tougas, Eric Moreau and Guy Barrette in particular.  JS was my personal tour guide all week, and Eric treated Julie Lerman and myself to lunch on Friday.  Overall, a great bunch of guys.  Thanks also to Jim Duffy for the chat on the plane to Philly.  Hope you got home after your delay.

Montreal .NET UG hosted a party one night, with some excellent beer and munchies.  JS and I loaded up on poutine before heading over.  There were giveaways, and I ended up winning an Aspose Total for .NET subscription because I dropped my business card in the pile.  Awesome!  That pretty much made the trip a wash for my company.  I’m looking forward to using that in the very near future.  JS had to catch his train home, and I had a little work to do, so we gave our door prize tickets to Julie (we’re each claiming 1/3 of anything she won).  Plus, I wasn’t going to try and navigate the underground by myself after a couple beers.

There was plenty of swag given away at DevTeach.  Dozens of thumb drives (I won a couple), as well as a big pile of books and I think 5 MSDN subscriptions.  Microsoft kicked in a copy of Visual Studio 2008 Professional, Expression Web and the Tech-Ed DVDs for all attendees.  Plus, the ever present messenger bag or backpack to take it all home in (from Leed’s, a local company).

Speaking of the Tech-Ed DVDs, they were produced with a beta of Silverlight, and don’t work with Silverlight 2.0 RTM.  Eric has more information about how to play the Tech-Ed DVDs.

Guy uploaded his photos to Sky Drive.  He’s the guy in the antlers.

So now that work is settling down a little, it’s time to do a little knowledge transfer with my team.  We have some good challenges ahead of us, and some great new knowledge to help us along.

DevTeach Post Con, Entity Framework with Julie Lerman

Umm, yeah.  That could turn into a conference unto itself.  After you run through the little wizard, you have something pretty easy to use, but under the covers, it’s amazing how much functionality and control they’ve baked in to a version 1 product.

Since EF originated with the ADO.NET team, it’s actually pretty performant.  In some tests Julie ran for a recent CoDE Magazine article, she shows the EF to be about 10x faster than Linq to SQL (which originated with the C# team, but has been transferred to the ADO.NET Team), and faster than even ADO.NET Data Adapters.

I’m pencilled in to present the EF at Pittsburgh .NET in February, and Nate and I are going to begin to incorporate it into Scrumr.  That mean’s there’s going to be some serious rearchitecting of the app, but it’ll be worth it in the long run.  As we go through the process, Nate and I will be blogging about our experiences.

DevTeach, Day 3

Today I got to meet Nitin, publisher of the awesome and free cheat sheets at http://www.refcardz.com/.  All free PDF downloads, covering a range of topics.  They’re introducing 12 new .NET cards next year, but already have Silverlight 2, Core .NET, C# and PowerShell.  Nitin brought some nicely printed ones for deign patterns and Silverlight 2.  This was a sweet bit of swag.

A lot of people stayed late at the UG party last night, judging by the low attendance at breakfast and bleary eyes in the early sessions.

My first session was protecting web apps against injection attacks.  In a way, I’m happy that we already do almost all of the recommended best practices.  There are a few things I need to touch up when I get back.

The Silverlight toolkit is very cool, I can’t wait to get more into Silverlight and what it can do.  The follow-up databinding session didn’t go so well, so not much there.

I did win a couple of USB keys today, and Rally Software gave me a handful of Matchbox-size Mini Coopers with their logo for looking at their software.  Their community edition may find its way into a project in the future as a test drive.

The afternoon is being spent with Rod Paddock and Jim Duffy.  Rod went through Ajaxing applications and a brief tour of the Ajax Control Toolkit.

The always hilarious Jim Duffy did a great talk on refactoring in VB.NET using the free Refactor! from DevExpress.  My team can expect to download and install this tool next week.

Last regular session is using Virtual Earth in ASP.NET apps.  Very excited about this.  My team at work can expect to see some of this next year.

DevTeach, Day 2

I’m in Markus Egger’s (Pubisher of CoDE Magazine) “Intro to Silverlight” talk, and he just dropped the bombshell that the next version of Silverlight will support out-of-browser experiences!  In 2.0, the browser is required to host the controls, but the next version can stand alone.

“Identifying Performance Benchmarks”.  Awesome.  This session alone will pay for the trip.  Cool tip:

select * from orders
GO

will execute the statement once

select * from orders
go 500

will execute the statement 500 times.  Perfmon + profiler = cool, especially when you overlay perfom stats on top of traces.

DB Maintenance Optimization.  Don’t use Database Maintenance Plans, create your own.  They’re not a great tool.  If you have to, research all their options, and choose as few as you need to–you can do some really dumb things.  Windows 2008 Server has scheduled job to defrag filesystem enabled by default.  Using SQL on a SAN, check out http://www.sqlcat.com/ for best practices.  Physical file fragmentation does exist on a SAN, but can be hidden by caching and buffering.  Diskeeper has some guidance.

Expression Blend is cool.  We got Expression Web as part of the conference swag, but we have Blend as part of MSDN.  Blend 2.0 is built in WPF, and parts of VS10 will also be built on WPF.  Blend 2.5 with the Silverlight tools was changed to be an SP.  WPF Spy tools can be used to poke around inside of blend.  Tips: if you don’t know a namespace, hover over the class and hit Ctrl+. to find all namespaces with that class.  I see some great potential for WPF enabled display of information.

Dynamic Data is awesome in theory.  It’s immediately most useful in master data admin pages, but special steps are necessary to secure dynamic data.  This is partly because of issues in securing ASP.NET routing.  Also, since it can rely on Linq to SQL, dynamic SQL is used, and the login user needs access to all tables we want to access, including the master data tables.  There is an example on securing dynamic data on Codeplex (access via http://asp.net/dynamicdata/ and go to samples).

Last session of the day is Query Execution Plans, with Brad McGehee again.  A lot of this I know from Kim Tripp’s webcasts in the past, but SQL 2005 has some differences over SQL 2000.  I’m amazed he can create such bad databases and queries on purpose for the demonstrations.  That takes effort when you’ve spent a lot of time figuring out how to do things correctly.

Tonight DotNetRocks recorded a session, and the Montreal .NET UG hosted a party at a nearby bar.  I ate poutine, which are fries covered with gravy and what translates into “cheese crap”, but what we call curds.  BTDT, and I don’t think I need another helping this week.