Comparing varchar to nvarchar in SQL

A few days ago I listened to a new episode of the .NET Rocks podcast, with Kimberly Tripp on the show. While she was going through the list of things every developer needs to know, one in particular caught my interest. She mentioned we should use the different types consistently in the database. Not using types consistently within your database can cause quite some performance loss. This is because SQL Server ‘upcasts’ the minor type to the higher type (example: varchar to nvarchar). As the term ‘quite some performance loss’ is a bit broad, I wanted to know how much this performance loss is exactly and if it’s worth rewriting/redesigning your database.

To test this case I’ve created a small database, named Performance, with a lot of records inside it. The database has 3 tables, named AsciiTable, MainTable and UnicodeTable. All three of them contain 2 columns, ID and a text column. The AsciiTable-table it’s text column has the type varchar(30), the MainTable and UnicodeTable it’s text column has the type nvarchar(30). I’ve created these to test how long some specific queries will take. At the end of this post I’ve inserted the script to create this database if you want to try it for yourself.

Read more →

Enhancing performance with 1 stylesheet and a custom handler

Including a lot of files in your website can impact the performance of your site. Your browser needs to request all those files from the webserver(s) and download them individually. Luckily this fetching is pretty fast and your browser can do multiple requests at once. However, there is a maximum to the number of requests a browser can make, so if you include 100 external files, will probably be (relatively) slow.

I’ve tested this by creating a new MVC 3 web application, copying the Site.css file 12 times and include all of them in the head-element of the page. Below you can see the FireBug and YSlow reports for this test page.

image

image

I’ve pressed the Refresh-button several times and came to the conclusion each individual file has a loading time between 5ms and 25ms.

Even though 13x25ms still is pretty fast, you probably understand it’s better to minimize the number of requests, because each request has some overhead and some have to wait for the other to be completed.

To minimize the number of files which need to be included in a website, devigners often create one huge CSS file and one huge JavaScript file which contains everything needed for the website to work. This way the browser only needs to make 3 requests to load the page, the HTML, the CSS and the JavaScript. An additional request will be made for the JavaScript framework you are using (if any) and some more additional requests will be made to fetch the images of the page you are loading.

Read more →

Developing a new Orchard content part and widget

Note:

Going through my blogpost draftfolder I noticed this post which I wrote about a year ago. Seeing a lot of time has gone into it I decided to post it anyway. It’s based on Orchard version 1.2, so things might have changed, but the basics are probably the same. Now for the real post.

I’ve got a new job where I was needed to create a new CMS website and add some client specific features on it. As Orchard is my preferred choice at the moment, it didn’t take me long to choose which CMS I was going to use.

To create some new, custom, features to the website I had to create new Modules and wanted to let them act as a Widget. A Widget in Orchard is much like a SharePoint webpart or an old-fashioned ASP.NET usercontrol.

Lucky for me the Orchard team has documented their work quite good, so I could use a lot of code from the ‘Writing a Content Part’ and ‘Writing a Widget’ tutorials.

One of the things I was asked to create is a widget which implements the SlideShowPro viewer. This widget is what I’ll use in this blogpost as an example.

First thing you need to do, if you want to create a Widget, is to create a new Content Part. A Content Part can be implemented as a new module in your Orchard website. You can use the code generation module for this, but if you prefer to do this manual, that’s also possible. If you choose to do this manually you need to create a lot of folders and files yourself as you need to start off with a new ASP.NET MVC 3 Web Application.

Read more →

Running OSX Lion on Windows with VMWare Workstation

I finally succeeded in setting up a VM with OSX Lion installed. Setting up an OSX environment in any VM tool has always been hard, but since Apple has decided to build for the x86 platform it has gotten a lot easier.
In the past couple of years I’ve tried to set up an Apple VM, but never really succeeded in it. Today I decided to try again. Apparently there are a lot of torrents out there containing OSX VM’s, so I’ve downloaded one of them to try out the OS.

After setting up the VM in VMWare Workstation and booting up I received an error telling me this guest OS couldn’t run with software virtualization and I had to enable hardware virtualization. My development machine has the VT-x option (Intel Virtualization Technology) in the BIOS, so enabling that fixed this issue.

image

Now, booting the guest OS again gave another error. VMWare Workstation told me the guest OS wasn’t Mac OS X Server. Changing this option to ‘Other 64-bit’ didn’t help either.

image

The virtual processors kept failing when booting up.

Lucky for me, the guys at SysProbs had already created a fix for this problem. Running the windows.bat file which is nested in the tar file of their download added a new option to the VMWare Workstation software

Read more →

Upgrade Orchard 1.3 to 1.4

As I’m busy designing and developing my new weblog I noticed a minor Orchard version was released. Because I’m in the starting phase of the development cycle, I decided to upgrade to the latest version.

This is rather easy, as you can just download the latest sources from CodePlex, extract and copy them over the old codebase (well, I deleted the original 1.3 files and copied the 1.4 files to a ‘clean’ folder).

Upgrading the Orchard sources broke several of my new modules, so I had to fix the broken code. After resolving those issues I pressed [Ctrl]+[F5] to see if everything was still working. It wasn’t.

Starting the site, I received a 404 error, because the pages couldn’t be found. Logs weren’t very helpful, aside from telling me some queries couldn’t run correctly. Deleting the /Sites/-folder in the App_Data did help me a bit, because now it showed me the normal ‘Orchard set up new site’ form.
Because I was starting to get a bit frustrated I decided to create a new website and have the connectionstring map to my old Orchard weblog database. This didn’t work either. Now there was an error the Recipes modules couldn’t be found or instantiated.

Read more →

Disable hibernate via registry when nothing else works

One of my development machines has a dual-boot to a 2008R2 environment via the Boot from VHD technique. This works all quite well, but today I received the message the C-drive was getting a bit full. Most of the time this isn’t much of a problem, just delete some log files, do a disk cleanup, empty the recycle bin and maybe use SpaceMonger to see what’s using up the rest of the space. Also, most of the time there’s about 500MB left free on the disk.

Today was different. Visual Studio wasn’t able to build my solution due to insufficient free disk space on the C-drive. Upon further inspection I saw a total of 0 free bytes were available. After doing the regular cleanup I had a stunning 119MB free on my C-drive. SpaceMonger had already shown me there was a hibernate file on the C-drive which took up 8GB. Quite strange considering I had turned off all of my hibernate options in Windows (I really don’t like hibernating). Also, this hibernate file doesn’t get generated when booting the machine in VMWare Player or VMWare Workstation.

All of my internet sources say you have to run powercfg -h off and reboot to completely remove the file. Problem with that is it gave (and still gives) me the following error:

Read more →

Get your references when pulling a project via NuGet

Because of a failing hard drive I had to re-install my Windows installation, including cloning all of my BitBucket repositories back to my projects folder.

Getting all the solutions back on the local development machine is very easy, but after opening, I discovered they couldn’t be build anymore. The reason for this: several references were missing. This wasn’t that strange at all, because these references were libraries pulled pulled down via NuGet and not pushed into the repository.

I had suspected there was something in NuGet which would make it easy to download the referenced packages. Reason for me to expect this is the packages.config file which is created after pulling down NuGet packages. This file contains all the information needed to re-download them, you see?

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="FluentAssertions" version="1.7.1.1" />
  <package id="Moq" version="4.0.10827" />
</packages>

At the moment there isn’t an option (i.e.: I couldn’t find it) to re-download the referenced libraries in the NuGet package manager. After doing a bit more research on the matter I discovered a page in the NuGet documentation called ‘Using NuGet without committing packages to source control’.

Over there they tell you to use the ‘Enable NuGet Package Restore’-option, which is available after right-clicking on the solution file.

Read more →

Update Orchard theme using SQL statement if the UI does not work anymore

If you create a theme for Orchard, it’s only a matter of time before you stumble across a yellow screen of death. I know this, because it happened multiple times to me. One of the reasons for these errors are the dynamic objects, which are used a lot in Orchard.

You won’t get compile-time errors with these objects, so they need to be handled with care.
Now, when a theme causes a yellow screen you are kind of screwed as you can’t do anything anymore on the website, like logging in to the admin area.

Lucky for us developers, the database isn’t obfuscated and we can make rapid changes to it. You can use this script to update your current Orchard theme and set it back to the default Theme Machine theme.

UPDATE [OrchardDatabaseName].[dbo].[default_Orchard_Themes_ThemeSiteSettingsPartRecord]
   SET [Id] = 1
      ,[CurrentThemeName] = 'TheThemeMachine'
GO

Run the above script on your Orchard database and you will be able to start developing again. If the above script doesn’t work, check the default_Orchard_Themes_ThemeSiteSettingsPartRecord table entries. You possibly need to change the Id parameter of the script to the one which is the same as in the database

Read more →

Getting the Orchard archive to work in your blog

A few months ago I decided to migrate my weblog from SharePoint to Orchard, because it’s more lightweight and better suited as a simple blog. I also started to develop some custom modules and themes for this CMS and have to say I like it!

One thing though, which has bothered me from the beginning, was the empty Archive block at the right side of my blog. I had done so much work to import the SharePoint blog entries to Orchard (a manual copy-paste action), so I knew the posts were there, I could even browse to them.

Why was it my posts weren’t visible in the archive block?

Today, I found the answer to my problem. It’s a small bug in Orchard when you set the blog to be the homepage of the site. Somehow the records in the [Orchard_Blogs_BlogArchivesPartRecord] table aren’t updated properly. The BlogSlug column should be changed to NULL and not contain the name of your weblog.

Once I knew this I changed the entries so they would contain the value NULL:

image

Note: You probably have got 1 record, but apparently I’ve done some adding and deleting of blogs, so I’ve got multiple. I can probably delete 3 of them, but just to be sure I didn’t.`

Read more →

ForeFront TMG does not work after Windows Updates (Internet Explorer 9.0)

A few weeks ago I was finally able to install some updates on my ForeFront TMG server, so I installed SP1 of Windows Server 2008R2, all other updates and Internet Explorer 9.0. After noticing my internet connection didn’t work anymore I logged in on the server and wanted to check what was wrong using the Management Console.

This is when I noticed the ForeFront TMG Management Console didn’t work anymore. Every treenode I selected resulted in an alert message stating ‘Member not Found’, ‘Refresh failed’, etc.

At times like this you wish you had created a backup of the server, before you updated it.

Lucky for me I was able to go to the internet with a direct line on my router and search for a solution. Because these updates were long overdue, someone must have had the same issue as me. This is one of the reasons I don’t like working with new/beta software of area’s I don’t know much about. I know a thing or two about managing a Microsoft network, but most things are magic to me.

An answer to my problem could be found on the ForeFront Technet forums of Microsoft.

To fix the issue you need to edit some file/html of ForeFront which resided on your local filesystem. The file which needs to be edited is: “C:\Program Files\Microsoft Forefront Threat Management Gateway\UI_HTMLs\TabsHandler\TabsHandler.htc”.
Open this file using Notepad as an Administrator.

Read more →