Wednesday, December 12, 2007

Interesting/weird feature of DateTime.ToString()

I was playing around with localization when I encountered the following behaviuor: I set time & number format to "French (Canada)", and wrote:


I got:

Instead of "/" I got "-".

I was looking around and couldn't find any documentation saying '/' is a special character in DateTime format string. Finally I used the following string which worked just fine:


Wednesday, December 5, 2007

How to list all installed sevice packs in C#

// Create WMI connection
options = new ConnectionOptions();

machine = "";

path = new ManagementPath(String.Format(
@"\\{0}\root\cimv2", machine));
scope = new ManagementScope(path, options);


// Query

query = new ObjectQuery(
"Select * from Win32_QuickFixEngineering");

managerTemp =
new ManagementObjectSearcher(scope, query);

//Get the results

returnCollection = managerTemp.Get();

(ManagementObject managementObject in returnCollection)

System.Console.WriteLine("*** New Item: ");
(PropertyData propertyData in managementObject.Properties)

System.Console.WriteLine(" {0} : {1}",

Wednesday, November 7, 2007

Disconnecting users from terminal services

I'm using terminal service at my home computer, and sometimes I forget an open connection from my laptop. Since I have only 2 administration connection I get 'too many connections error.

I found this post which explains how to disconnect someone remotely from terminal services:
* qwinsta /server:
List connections.
* rwinsta /server: 3
Disconnect session (3)

Friday, October 12, 2007

ASP.NET 2.0 Applications not working

After installing my Win2003 server (x64) I couldn't make ASP.NET 2.0 application to work. Usually I would check the ASP.NET tab in the IIS MMC, but that tab wouldn't appear (if it does appear verify that the correct ASP.NET version is assign to the application & in the "Virtual Directory" tab, there and "Application Settings" with execute permission - "Scripts" at least)

The solution on the web didn't work:
Microsoft comments: If a previous version was not uninstalled correctly, please regedit eliminate all versions except in the following locations:
HKET_CLASSES_ROOT\CLSID\{FD5CD8B1-6FE0-44F3-BBFB-65E3655B096E} \InprocServer32\

Also re-installing .NET Framework 2.0 didn't work, nor registering ASP.NET:
%SYSTEM%\Framework64\2.0.XXX\aspnet_regiis -i

Finally I found a solution (not to the MMC yet): use a separate application pool. After creating a separate application pool for the ASP.NET 2.0 applications everything worked just fine.

Monday, October 1, 2007

How to enable Directory Browsing in IIS on Windows Vista

For some reason Microsoft moved the "Directory Browsing" feature in Windows Vista's IIS to the following location:
Control Panel ->
Programs and Features ->
Turn windows features on and off ->
Internet Information Services ->
World Wide Web Services ->
Common Http Features ->
Directory Browsing

In windows Vista you can also replace the default directory browsing with other ways to browse directories very easily (see here for example).

Wednesday, September 26, 2007

C#: NULL key in Dictionary<>

Few days ago I got an exception while enumerating a Dictionary<>. It was a null pointer exception for a key object. Since the keys in a dictionary may not be null I've started to dig and found the reason - multi threading writers to a dictionary without locks can cause null key (even if the writing was before the enumeration).

Solution: locks.

Friday, September 21, 2007

Access MDB on windows 64 bit using C#

Few days ago I had to install software I wrote in C# which uses Access MDB files on a Windows 2003 x64. After installing the software (compiled for 32bit) I got an error saying the Microsoft.Jet.OLEDB.4.0 provider is not installed.

After a short search I found out there isn't JET provider for x64 systems, however, Windows 2003 comes with 2 sets of ODBC providers: 64bit and 32bit, which can be accessed with 2 separate programs:
c:\windows\SysWOW64\odbcad.exe - 32bit providers
c:\windows\system\odbcad.exe - 64bit providers

When checking the list of x32 providers I found Access MDB provider! So at this point I started to check how to force .NET applications to run in x32 mode. 5 minutes later I had the solution - the .NET SDK utility CorFlags.exe:

CorFlags /32bit+ MyProgram.exe

Works like a charm. Now my program runs as before with Access MDB on Windows 2003 x64.

UPDATE: Better solution with the same results -
Project -> Properties -> Build
Set "Platform Target" to x86

Monday, September 3, 2007

SQLServer database grows big

I was looking around for a tool that will tell me how much space each table in my SQLServer database. After little search I found this sql script, which really helped me finding which table eat away all the space in the database.

btw - sometimes people forget that if you don't define your backup mode to "Simple" the transaction log will grow unless you backup the database.

Saturday, August 25, 2007

IE opens KMZ as ZIP

Yesterday I've decided to play around with Google Earth so I wrote a small KMZ file, which I've uploaded to my site. However when I've tried to download the KMZ, IE opened the file as ZIP.

After a short search I found out the reason: my hosting site didn't add the Google Earth MIME extension (see the bottom of that page) to the Apache server. Since I don't have the privileges to add the extensions I was looking for a work around. One way I found was to put my KMZ in Google Pages. Ugly and probably not allowed with Google Pages license - putting a file in Google Page as storage only.

After some more digging I found the following solution - create a script that add the correct MIME header (I used PHP but I guess you can do it in ASP very easily):

header('Content-type: application/');
header('Content-Disposition: attachment; filename="myfile.kmz"');


Wednesday, August 15, 2007

Microsoft CRM - Outlook client doesn't load...

I've just finished fighting with MS-CRM Outlook add-in. It was really time consuming for no good reason.

The battle story:
The MS-CRM was working just fine from the IE interface but I wanted the Outlook interface. After installing the Outlook add-in I got the following message when I started Outlook:
"There is a problem communicating with the Microsoft CRM Server. The server might be unavailable. Try again later. If the problem persists, contact your system administrator."

I found two posts in the MS-Knowledge Base which didn't helped at all:

After digging some more in the MS news groups I found the solution (for me, and I guess for most poeple with CRM out-of-the-box). You can skip to step 3 in order to verify this is your problem with the CRM.

1. Add the CRM site to the trusted sites list in IE (Tools->Internet Options->Security, click on "Trusted Sites" then "Sites" and add the site URL).

2. Verify that the trusted sites passwords are stored in IE (Tools->Internet Options->Security, click on "Trusted Sites" then "Custom Level", go all the way down to "User Authentication" -> "Logon", and choose "Automatic logon with username and password")

3. Open MS-CRM in Internet explorer and insert the password. Close IE. Open again and verify you don't have to enter the password again. If you do, you did something wrong in steps 1 or 2.

4. Open Outlook.

Sunday, July 1, 2007

Leaking Form.ShowDialog

In the last few weeks I was debugging an application to find leaking memory. I found lots of tips in this MSDN article. Something I found few times is that people are not aware that you MUST call Dispose() after you call ShowDialog (see Microsoft docs).

The simplest way to create a memory leak with a form:
Form form = new FooForm();
form.Owner = this
After this code block will finish the form "form" will stay in the memory because the owner form holds a refrence to the form in OwnedForms. To free the memory you must call form.Dispose();

Monday, May 28, 2007

Fast DataTable loading from IDataReader

I was using the Load method of DataTable to load data from IDataReader the other day, and while profiling the application I found out that this is my program bottleneck.

I've just wrote a quick & dirty function which does the same task much faster:

private static DataTable ReaderToDataTable(IDataReader reader)
int fieldCount = reader.FieldCount;
DataTable result = new DataTable("Query Result");
for (int i = 0; i < reader.FieldCount; i++)
DataColumn column = result.Columns.Add(reader.GetName(i));
column.DataType = reader.GetFieldType(i);

object[] row = new object[fieldCount];
while (reader.Read())

return result;

Friday, May 25, 2007

Nepali Xbox

I took this picture last November during the "Frozen Lakes" trek, Nepal.

Friday, May 18, 2007

Creating a MOSS Demo/Test machine

I've being installing a testing virtual machine for MOSS 2007 related application. While searching the internet I've found this post which describe step by step how to install MOSS machine.

Memory Debugging in .NET applications

Long time ago I found a post regarding memory debugging in .NET applications:
Analyzing Common CLR Performance Problems

That post address lots of memory leak types, while usually I encouter memory leaks from the heap. Here's the summary how to find heap memory leaks:

1. Start the windows debugger: WinDbg (can be downloaded from here).

2. Attach to the target .NET process

3. Load the SOS module, in the WinDbg console write:
.loadby sos mscorwks

4. List all the allocated objects:
!dumpheap -stat

At this point you can break & resume the program as you wish.
Other Useful commands:
!finalizequeue - show the list of objects waiting for finalize thread
!threads - running threads
!eeheap -gc - show the object generations in the GC

Full (?) list of commands can be found here