Google
 

Monday, March 8, 2010

Changing AJAXtoolkit:CalendarExtender day format

AJAX toolkit has a set of awesome controls, and very customizable too. But one property that is not customizable OOB is how the day names are displayed in the Calendar extender.
The displayed format is two letters only. But what if you want it to be displayed in three letters?
Here a small cosmetic surgery (i.e. code changes).










BeforeAfter



So, what does it take to do it successfully?
I opened CalendarBehavior.debug.js, which contains the debug version of the extender's JavaScript. Day names were obtained from an array named: dtf.ShortestDayNames:

dayCell.appendChild(document.createTextNode(dtf.ShortestDayNames[(i + firstDayOfWeek) % 7]));

Searching the library code, I found that this array is defined in MicrosoftAjax.debug.js. as:

ShortestDayNames":["Su","Mo","Tu","We","Th","Fr","Sa"]

And fortunately, another array was defined with three letters names:

AbbreviatedDayNames":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]

So all what it takes is to replace ShortestDayNames with AbbreviatedDayNames in both CalendarBehavior.debug.js and CalendarBehavior.js:

dayCell.appendChild(document.createTextNode(dtf.AbbreviatedDayNames[(i + firstDayOfWeek) % 7]));

And build.

It's great to have the source between your hands :)

Saturday, February 6, 2010

My Twitter account

I'm not a big fan of social networking sites. But I think twitter can be a great information sharing platform. Follow me, I don't intend to make so much noise anyway :)

Friday, January 29, 2010

Tip: turn auto close Off for you SQL Server databases

On a development machine, I had a high CPU usage for the SQL server service. To understand the reason, I looked at the SQL Server logs (From SQL Server Management Studio - SQL Server Logs).


As you may notice from the screenshot above, the activity of starting the reporting service database was recurring again and again.
I checked the database options, and the noticed that the auto close property was set true. This explains why SQL Server tries to start the database at every connection.
If the Auto close property is set to on:
the database is closed and shut down cleanly when the last user of the database exits and all processes in the database complete.
As quoted from msdn.
Unfortunately, the property was set to true when the database was created during the SQL server installation.
Turning Auto close to false (off), and maybe restarting the service, returned the CPU usage of the SQL Server service to a normal level.

Friday, January 1, 2010

Articles I read in 2009

A new year, and as a habit, I share the a list of articles I read in the past year, 2009.
It was a tough year on the personal, career and study levels, I wish I can contribute more to the community in the new year through blogging, article writing and open source software.

2008 list can be fond here
2007 list can be fond here

Thursday, November 12, 2009

Getting started with SharePoint 2010

SharePoint 2010 is coming with a lot of new features and if you are seriously interested in SharePoint, you should start build your 2010's knowledge. My colleague Mourad Askar posted on his blog about SharePoint 2010 Information and Tutorials which I find very informative.
On Microsoft's SharePoint 2010 site, you can find tutorials, videos and you can register for the beta.

One important thing, SharePoint 2010 will no run on 32Bit machines. If you have a core 2 due processor, it supports 64 bit. And if in doubt and want to run SharePoint on a virtual machine, check VMWare's tool that tests if your processor is capable of running a 64bit guest OS.
http://download3.vmware.com/software/wkst/VMware-guest64check-5.5.0-18463.exe

Personally, I have a core 2 Due Laptop with Vista 32 bit installed. I installed the 64 bit edition of Linux Ubuntu 9.04 and can host Windows 2008 64bit OS using Virtual Box. What's good about this scenario is that Ubuntu's memory usage is light and gives a good space to host virtual machines.

Saturday, July 11, 2009

Using PowerShell and SMO to change database columns collations

Changing a SQL serve database columns collations manually can be a tedious task. I have a database that I want to change the collation of all its non system columns to "Arabic_CS_AS".
Here is a PowerShell script that uses SQL Server Management Objects (SMO) to do this task:
(note that I load the assemblies with version 10.0.0 which is the version of SQL server 2008 I have installed on my system)


[System.Reflection.Assembly]::Load("Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91")
[System.Reflection.Assembly]::Load("Microsoft.SqlServer.ConnectionInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91")

$con = New-Object Microsoft.SqlServer.Management.Common.ServerConnection

$con.ConnectionString="Data Source=.\SQLExpress;Integrated Security=SSPI;"

$con.Connect()

$srv = New-Object Microsoft.SqlServer.Management.Smo.Server $con
$db = $srv.Databases["test"]

foreach ($table in $db.Tables)
{
if($table.IsSystemObject)
{
continue
}

foreach($column in $table.Columns)
{
if(-not ([string]::IsNullOrEmpty($column.Collation)))
{
$column.Collation = "Arabic_CS_AS"
$column.Alter()
}
}
}

$con.Disconnect()

Thursday, July 2, 2009

Not calling Dispose can cause InvalidComObjectException

During load testing an application that performs thousands of operations against Active Directory and under high load conditions. The process stopped working and our logs showed this error:

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been
separated from its underlying RCW cannot be used.

Searching for this error, most answers on forums referred to trying to access a COM object from a thread other than the thread that created it. We use multithreading, but we did not use objects across threads.

Logs pointed us the location of the code where we should investigate. I made a review on a method that was called thousands of times and creates DirectoryEntry instances. The DirectoryEntry was not disposed!!

We were not sure that this can cause the above exception, but it was a bug and it needed to be fixed anyway. We fixed it and reapplied the scenarios that caused this exception, and it disappeared.

Other that understanding a new reason for that mysterious exception, there are some useful lessons:
  • Proper logging can help identifying errors quickly.
  • Failing to dispose disposable objects causes performance penalties that some developers underestimate their effect. It can make your application stop working!!
  • Early code review is important to spot these kinds of errors.
  • Test your application under real-life conditions.
  • Using memory profilers and dispose trackers is worth trying in some cases.