Getting familiar with .net 3.5

I started playing around with .net 3.5 today.  I wanted to take a look at the TimeZoneInfo class first, since that new class conflicted with a custom class I wrote for Property Center.  I’m happy to say that the new MS class does everything that mine does, so I can migrate my code to use the MS TimeZoneUtil class in the future.  They finally provide an easy way to iterate all timezones (listed in the current machine’s registry – which seems to be all current timezones in the world), not to mention easy ways to convert datetimes between each timezone.  It factors in all of the rules related to daylight savings as well.

After that, I looked into linq to sql so that I can start playing with actual data in my sql database.  I didn’t really feel like using the Object Relational Designer to generate the entity classes because truthfully… designers really don’t do it for me.  They ship a commandline tool called SqlMetal that does what I wanted.  If you have used subsonic’s generator, you’ll be a little disappointed with the options that SqlMetal provides.  For example, I prefix my tables with pc_, but i don’t want that showing up in my object model.  I couldn’t find a way to have sqlmetal ignore the table prefixes.  It also generates one large file containing all classes, which is a little annoying, imo. 

You can find more information on how to use SqlMetal at: http://msdn2.microsoft.com/en-us/library/bb386987(VS.90).aspx.  And as a side note, SqlMetal.exe exists in C:WindowsMicrosoft.NetFramework3.5.

Property Center running on .net 3.5

I got Property Center running on .net 3.5 tonight.  Honestly, it wasn’t a lot of work.  There were some minor conflicts with the internal timezone class that I use, and I had to enable asp.net 2.0 web server extension with the vs.net 2008 virtual pc image.  Other than that, things compile without any major problems and the site comes up as I expected.  It was interesting to note that as far as IIS is concerned, it still uses asp.net 2.0.

I’m really looking forward to doing some performance tweaking with linq and some of the 3.5 features.  I’m guessing that the site will begin a slow transition away from nHibernate as I get more comfortable with linq and linq for _____.  nHibernate has been great for me, but it has also made me lazy as far as performance tweaking.  It’s not nHibernate’s fault, since it does support performance tweaks quite nicely.  I’ll post my trials and tribulations as I work with the new version of the .net framework.

How to restore a db when the db is in use

I kept running into issues when I tried to restore a database from a backup file.  The error I kept getting was:

Restore failed for Server ‘localhostSQLExpress’.

Additional Information:
System.Data.SqlClient.SqlError: Exclusive access could not be
obtained because the database is in use.

For local sql instances, it’s not a huge deal since I can just restart the db server and clear the connections.  But in a managed/shared environment, that’s not possible.  I googled quite a bit for a solution, but didn’t really find anything that would work.  So I asked the newsgroups for some help and they came up with putting the db in single user mode before restoring the db.  That was cool and all but ended up locking me out of the db at my hoster.  So what I had to do was run the single user mode command and the restore command as one query.  Something like:

ALTER DATABASE  [your_db_name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

RESTORE DATABASE [your_db_name] FROM  DISK = N’C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLBackupyour_db_name.bak’ WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10
GO

The restore line can automatically be scripted for you by Sql Management Studio.  Just click the Script icon at the top of the restore dialog.  Maybe MS will add an option to clear connections on restore in a future version of the management studio… One other note is that the restore command will automatically set the restored database in multiuser mode.

Hope this helps someone…

Edit:

If you need to set the database back to multi user mode, you can use the following command:

ALTER DATABASE  [your_db_name] SET MULTI_USER WITH ROLLBACK IMMEDIATE

Parallel Fx

I read a little bit about the concurrency APIs that will ship with .Net 3.5.  It seems that they are FINALLY making it easy to integrate concurrency into an application without having to worry about locks, threads, etc.  I’m not saying that knowing those low level concurrency programming concepts is a bad thing, but it’s nice to see that there is a super easy way to place concurrency into your program.  I read this article about PFX (Parallel Fx) which shows exccellent examples like the following:

void ParMatrixMult(int size, double[,] m1, double[,] m2, double[,] result)
{
  Parallel.For( 0, size, delegate(int i) {
    for (int j = 0; j < size; j++) {
      result[i, j] = 0;
      for (int k = 0; k < size; k++) {
        result[i, j] += m1[i, k] * m2[k, j];
      }
    }
  });
}

 
Also, I found it very useful to listen to this episode of Hanselminutes where Scott interviews the Steven Toub.  They talk about how MS trying to make parallel computing easier on all levels for .net.  It was interesting to hear that Steven didn’t really think that pfx would help web apps much since they run on a webserver that is already pretty optimized for parallel processes.  I’d be interested in seeing a performance graph that shows site performance using pfx versus not using pfx, against a timeline of requests per second.

It’s safe to say that .net 3.5 is getting me excited about .net programming all over.  I think they’re coming out with some pretty cool things that are sure to make life easier (and probably complicated in new ways as well). 

Thoughts about this site

Now that things aren’t so hectic with Property Center development, I hope to get back into the swing of things and start posting more regularly.  I’ve also been thinking of what to do with this site… From the sounds of things, Graffiti cms might be more appropriate than Community Server as the engine for this site.  I’d like to get away from the separate blog per user concept and do something where there is only one entry point of the site while still allowing multiple contributers.  I also think that I’d like to get away from having the date embedded in the friendly urls.  I could go either way with the date thing, since I know I’ll have some posts that are useful for chronological organization, but I’ll have other posts that I don’t want an age associated with.

Community Server doesn’t really fit the role of where I want to take this site, but hopefully Graffiti will.  If not, I may look into writing the software by myself to get acquainted with some newer MS offerings (.net 3.5, linq, mvc, etc…).

The only bummer that I’ll have to work out is what to do with the pictures.  I don’t want to lose the pictures and really don’t feel like moving them all to Flickr.  I guess I could write an image gallery app, but that really doesn’t thrill me. 

Property Center Oct 2007 Update

This last week, I pushed live a pretty significant update for Property Center.  This update has been a long time in the making… damn near 9 months actually.  I’d wager that I refactored about 70% of the code for Property Center.  Let that be a lesson, if you think you may want to support localization at some point, it’s better to do it early than go back and add it later.  But anyway, the update is out there and the response has been excellent. 

I wanted to thank OrcsWeb for the amazing job they do.  I have never been so satisfied with a hosting company that i am with OrcsWeb.  They will definitely get all of my future Asp.net business.  I was updating the database and thought something went wrong.  So, I tried and failed to restore to a backed up version.  At that point, I started to get worried and called their tech support.  Within three minutes, they had my database restored and everything was happy again.  Again, I tip my hat to that kind of support (especially when they have that kind of response level at 11pm).

Overall the update went really smoothly.  I’m completely satisfied with the current version of Property Center and look forward to adding additional features to the platform.

Eat, drink, and be merry

Last night, I got back from a nice vacation to Europe.  Had I not donated my camera to Germany, I would post some pictures, but what can ya do…

I spent the first 4 days in Varna, Bulgaria.  Actually, it was Golden Sands which is a small town outside of Varna.  It’s located on the Black Sea and has become quite a nice European resort town in the last few years.   I stayed in a nice hotel along the sea and can definitely see myself going there again.  Unfortunately, it was out of season by about two weeks, so next time I’ll probably go in July or August.  As far as I know, I was the only American in Golden Sands.  It seemed that Germans tend to holiday there the most.  As far as the food goes, it was pretty amazing in my opinion.  They serve a lot of fire roasted meats (pork, chicken, etc) and use earthenware to keep the meals nice and toasty.

After Golden Sands, I took a short one hour flight to Sofia.  Sofia is Bulgaria’s capital and is a nice sized city.   After checking into my room and taking a short nap, I was ready to just hang out in my room with my book.  I headed down to the hotel restaurant for a pretty tasty dinner and afterward went to the hotel bar for a drink.  While I was there, I was overheard talking with the bartender a little by a guy from the States.  Turns out that he is a director who was in town doing a feature film for the sci-fi channel.  I have to admit that it was pretty nice to speak English with someone and we ended up hanging out that night.  So instead of chilling out in my room, I ended up going out till 4am.  The next night, I had a traditional Bulgarian meal and followed it up by going out to different bars & clubs…  yet another late night, this time I got home around 6am.

A short rest later, and I found myself on a 2 hour flight to Munich.   I got into the hotel after a quick detour to a small town outside of Munich (a bit of a miscommunication between the cabby and myself) and shortly met with Kevin and Jason.  Little did I know that they were coming from a stadium where they had purchased 3 tickets to a game that night.  So, I had just enough time to put some shorts on before heading out to the Allianz Arena for a soccer match (between 1860 and FC St Pauli).  The game was awesome… the energy level at soccer games far exceeds what I’ve experienced at football and baseball combined.  Later that night, we went to Hofbrau House for a couple beers and some excellent food.  We got to the grounds around 8am on Saturday, but weren’t prepared for how busy it was going to be.  After watching the opening day Oktoberfest parade, we got into the Hippodrome tent.  Note to self… it’s considered an insult to try to pay a guard to get in.  We hung out in the Hippo for around an hour and even ran into the old servers that we met the last time.  But they were unable to help us find a seat for all 5 of us (Phil, Whitney, Kevin, Fox and myself).  So, we all left the grounds and headed to the  Viktualienmarkt beer garden.  The Viktualienmarkt beer garden serves beer from all 6 of Munich’s largest breweries, whereas other beer gardens only serve one type of beer.  Unfortunately, the night’s festivities resulted in me losing my camera… For the last day, we got up early again and headed to the Hacker Pschorr tent.  We easily got into it without a bracelet, and shared a nice table with some Germans.  Phil and I ended up being the last people to hang out, and decided to ride a coaster before leaving the grounds around midnight. 

Anyway… that’s the gist of the trip.  I was pretty wrecked from Oktoberfest, and am just feeling better today.   

Welcome Cayden

Around 6:12pm on August 14th, Cayden William Geurts was born and I became an uncle.  I’m looking forward to watching the changes as he grows and helping him with anything he needs along the way.  I took some pictures with my new camera when I was over there.  I got a Canon SD850 IS and couldn’t be happier with the small camera.  I wanted something that was small enough for me to take anywhere, and the picture quality seems pretty good.

Anyway, have a look at some of the pictures that I took while visiting Cayden, Bill, and Kari

Cayden GeurtsCayden Geurts 

My fix for “Validation of viewstate MAC failed” error in IE

Once again, I have cursed the IE team repeatedly… I am ashamed to work on web applications knowing that I have to support such a pile of shit. 

Ranting aside, I ran into an IE only issue with asp.net.  Specifically, I was getting “Validation of viewstate MAC failed” that has randomly plagued developers for years.  My issue arose for a page that has an asp.net gridview and some other controls that do an autopostback.  My page would completely load, but whenever I posted back (form submits worked, however), the app would crash in IE.  Searching the internet didn’t really yield much information and all the “solutions” didn’t fix my problem.  Well, it turns out that I had a nested form within my asp.net form (the main one with runat=”server”).  Removing the nested form fixed the issue.  I’d suggest that if you’re running into the same error, examine your markup, as firefox tends to be more lenient.