Sunday, December 16, 2007

Windows 2008 Hyper-V Installation - Login

I was checking out Windows 2008 Hyper-V RC1. Downloaded the ISO image and installed it. Everything went pretty well with minimum user intervention. After a couple of auto reboots the login window appeared and I had only one option - Other Login (for the core installation).

I was scratching my head trying to figure out what login I can use since the installation didn't ask me to create any login. So I tried out a couple of well known default username and password and finally I got in with the Administrator & blank password combination.

Once I logged in, I was presented with the good old Command prompt. For those of you who are used to the Windows interface, this might be a bit of a shocker.

The next thing I did was to enable Hyper-V in the core server deployment. This was done with the command:

Start /w ocsetup Microsoft-Hyper-V

A reboot is required once Hyper-V is enabled. Please note that the command is case sensitive so you must type the command exactly as seen here.

Tuesday, December 11, 2007

How to set up SQL Server to listen on multiple static TCP ports

Did you know you can have your MS SQL Server listen on multiple TCP ports? I find this feature very useful since I run my DB server on a specific port and often run into clients that require to have database connection on a different port because it falls inline with their security practice.

Here's how you can do it:

1. Start SQL Server Network Utility
2. Select TCP/IP and click Properties button
3. Enter the port numbers (separated by commas)
4. Click OK twice
5. Stop & restart SQL Server for the change to take effect

Tuesday, December 4, 2007

Terminal Services Client (MSTSC) and Vista/2008

A few months back, I wrote a blog about as you can see here.

Well, in the newer version of MSTSC for Windows Vista and Windows 2008, the "/console" option is no longer available. However, you can use a new switch "/admin".

This new switch has an advantage that "/admin" session can still be created when the session count has maxed out. Also, the "/admin" sessions don't count toward the session limit that may be configured on a terminal server to limit the number of sessions.

Sunday, November 4, 2007

Unable to Start Debugging on the Web Server

One of the error you'll probably run into when setting up a new ASP.net project is the "Unable to Start Debugging on the Web Server". Most of the time, this error can be fixed by enabling Integrated Windows Authentication. You can do this by:

1. Launch IIS Management Console.
2. Right click on the website and select Properties.
3. Click on the Directory Security Tab.
4. Check the box that reads "Integrated Windows authentication".

If that doesn't work, you'll need to make sure that Keep HTTP-Alives Enabled option is checked. And if all fails, register the .net framework again and check your permission settings.

Good Luck!

Friday, October 19, 2007

Iterate through HashTable

What is a Hashtable?

A Hashtable is a collection type object that is used to store key-value combinations. In a way, it's very similar to a good old Dictionary object. You can retrieve stored value/object by either keys or by associated value. However, the performance is at its best when you search with keys.

Let's see how we can create and use a hashtable:

Dim htCars As New Hashtable
htCars.Add(1, "Buick")
htCars.Add(2, "Chevy")
htCars.Add(3, "GM")

Dim myCar As String
myCar = htCars.Item(2)

This code fragment creates a hashtable object and adds three items to it. Then it calls the Item property to get the value for item with key 2. Item is the default value for the hashtable so myCar = htCars(2) would have produce the same result.

OK, so you've got a hashtable built and can get a single value out of it. But how do you iterate through all the items that were stored in it?

One way to do this is to use the Keys collection to pull out the values:

Dim carID As Integer
For Each carID In htCars.Keys
Console.Writeline(carID & " - " & htCars(carID))
Next


Another way is to use the DictionaryEntry object as in:

Dim dictEntry As DictionaryEntry
For Each dictEntry In htCars
Console.Writeline(dictEntry.Key & " - " & dictEntry .Value)
Next dictEntry


And last but not least, you can run through all the items stored in the hashtable by obtaining the enumerator object through the IDictionaryEnumerator which is returned by the GetEnumerator function:

Dim myEnumerator As IDictionaryEnumerator = htCars.GetEnumerator()
While myEnumerator.MoveNext()
Console.Writeline(myEnumerator.Key & " - " & myEnumerator.Value)
End While

Hashtable are easy to use, efficient & fast. I often use it to preload frequently use data like reference tables and it really improves the application performance nicely.

Monday, October 15, 2007

Using Enumerations To Document Your Code

Enumeration is a great way to assign easy to understand & remember textual names to your values. Consider the example:

Public Sub CityWork(ByVal CityID As Integer)
If CityID = 0 Then
'do something
ElseIf CityID = 1 Then
'do something
ElseIf CityID = 2 Then
'do something
Else
'do something
End If
End Sub

By the look of that, the code is pretty hard to understand as you have to remember what all those numbers are to associate with their function. To clarify things a bit, we can modify the above code using enumeration:

Public Enum CityTypes
SanDiego
SanFrancisco
SanJose
End Enum

Public Sub CityWork(ByVal CityID As CityTypes)
If CityID = CityTypes.SanDiego Then
'do something
ElseIf CityID = CityTypes.SanFrancisco Then
'do something
ElseIf CityID = CityTypes.SanJose Then
'do something
Else
'do something
End If
End Sub

Now this code is pretty much self-documented. It makes it so much easier to understand and will also allows you to take advantage of intellisense to help you code faster.

By default, the first enumerated value (SanDiego in this case) will have a value of 0. You can change that by explicitly assign an integer to it. The next enumerated value, if not specified, will be increased by 1 from the previous value (SanJose = 6)

Public Enum CityTypes
SanDiego = 1
SanFrancisco = 5
SanJose
End Enum

If you write your code this way, you'll find that it's much easier to understand, you can code faster, it's less prone to errors and at the same time, you pretty much self-documented the code.

Friday, October 12, 2007

Troubleshooting ASP.net Application with CustomErrors

There are many ways to troubleshoot IIS application errors. Here I will discuss a simple yet effective way to troubleshoot your IIS applications.

In the Web.config, under System.web node, there's one section called customErrors. By default this is commented out and the mode set to

<system.web>
<customerrors mode="RemoteOnly">
<system.web>


With this setting in place, if you run into some error, chances are you will only see a generic runtime error that reads:

An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

In order to see what's going on, you will need to modify the Web.config file so the customErrors tag read:

<system.web>
<customerrors mode="Off">
<system.web>


Note that this should only be done on development workstations as the detailed error message could expose information you don't want users to see like identity impersonation information... As for production, try to run the application on the server to see the error.

Now that you can see what's actually causing the error, it should be easy to narrow the problem to a particular line number and take corrective action.

Thursday, October 11, 2007

Fixing Fail To Access IIS Metabase Error

I often run into this error message for various reasons like doing a reinstallation, machine upgrade or preparing a workstation for a new co-worker...

This error is fairly simple to fix but if you don't know how, it could drive one crazy. You often run into this error after you install Visual Studio 2005 and then try to run a webpage on your machine. The error you encounter will read something like this:

Failed to access IIS metabase.

If so, you may have installed IIS after the .NET framework has been installed. To fix this, try to repair your ASP.NET installation and set up all of the appropriate ISAPI extension mappings using the aspnet_regiss utility in the .NET framework folder.

aspnet_regiis -i

This utility is found in the .NET framework version number under your Windows installation folder.