Wednesday, October 10, 2007

Mobile RSS Reader - Viigo

It's been some time after my last blog, i just moved to a new company and found several new things to play around ;)
My wife just bought a windows mobile 6 PDA phone for me last month :D so I also spent some time trying to find nice softwares to install.
So as usual, the easiest way to keep up with the latest news is the RSS, so I have been searching in the internet for rss reader for mobile, and I finally found a very nice one : Viigo (http://www.viigo.com/)
It can run on many popular mobile devices such as BlackBerry, Java, and the most importantly for me is Windows Mobile ;)
The interface looks good and it is very easy to add our own channels (RSS subscriptions), it even has some popular channel list suggestions that we can easily add into our own channels.
So every evening before I go to bed, I will update all the subscription contents, so in the next day I can read them along the journey to the office and also on the way home ;)

Thursday, August 23, 2007

XML & XPath Expression

When we have an application which is having XML Files as the data storage and need the fastest way to only read the data, XPath will be a good solution.

How to loop the data from an xml into XPath is quite simple.
I will be using .Net code below to do this.

XPathDocument xpDoc = new XPathDocument(@"C:\Temp\data.xml");
XPathNavigator xpNav = xpDoc.CreateNavigator();
XPathNodeIterator xpIter = xpNav.Select("/root/row");
while (xpIter.MoveNext())
{
Console.WriteLine(xpIter.Current.GetAttribute("id", string.Empty));
}


The code will simply load the data.xml and then loop the data and write the ID to the console.

There will be occasions where we need to perform more complex queries to the data which we can do it quite simple such as in the SQL statement below:

Select * From data

Where colA In ('AA', 'ZZ')
And colB = 'X'
And colC Like '%123%'


We can achieve the same result with XPath by using this expression below :

XPathNodeIterator xpIter = xpNav.Select("/root/row[(@colA = 'AA' or @colA = 'ZZ') and @colB = 'X' and contains(@colC, '123')]");

There is a lot of ways that we can use in XPath, you can find the complete references in http://www.w3.org/TR/xpath

XML is always an interesting type of data that we can use, there is a lot of database technologies nowadays which has actually supports XML type of data such as SQL2005 where I heard we can set the indexes in the XML type of field ;)

Unicode content in Cookies

This is another small small things but can get to the nerves ;)

So basically, I was doing some changes with a Taiwan web application, previously it was using Session to store some information and right now because of we're integrating with other application, we need to use the cookie instead so the information can be shared.
Note: When using cookies, if the information is confidential, you may need to consider encryption.

After i modified the application and tested it in one of the server, everything is working perfectly, until I tried it in the other server, just to make sure that this is working fine as well. And the unexpected actually happened, the unicode characters were corrupted, they are becoming question marks (????).
Firstly I thought that the server probably missing some language pack, and then I installed the language pack to the server and turned out, it was not helping either. Then I tried this application into another server again (it is fun to have a lot of servers to play and test with hohohoho), and some of them were able to save the unicode correctly and some of them didn't, including my own PC :(

I was kept thinking, what is the difference between these machines, why some of them are working and some of them aren't. I looked into the cookie file in the my local machine, the cookies which were saved correctly are having UTF-8 as the encoding and the cookies which are corrupted were having ANSI as the encoding.

So in the end, actually instead of thinking why UTF-8 and ANSI, there is a simple solution.
Use HttpUtility.UrlEncode when saving cookie, and use HttpUtility.UrlDecode when reading back from the cookie.
Using this way, we don't need to worry whether the characters will be corrupted because of some machine settings :)

Sounds easy rite? hhhmm... it took me almost 2 days browsing and browsing and then have this solution come to my mind. Getting older I guess hahaha ;)

Thursday, July 12, 2007

ORM - SubSonic rocks

It's been a while since my last post, just delivered a project last week and finally got time to browse around again hahaha :)

As usual, if i need to update my self with the latest news, i will go to www.asp.net and find my self like living in the rock age again ;)

And as usual as well, we can find very interesting things in Scott Guthrie's Blog (http://weblogs.asp.net/scottgu)

I've been interested lately with the ORM tools, such as nHibernate, ActiveRecords (Built on top of nHibernate). Since previously I used a port of JAVA Persist ORM, it really helped in the development phase since I don't have to do all the DAL classes, Stored Procedures, etc. It generate the code for us based on the provided xml schema (We need to provide this with the relationship between objects).

This time, I found a very interesting tool, called SubSonic.
You can find the website of the tool in
http://www.codeplex.com/actionpack (Old one)
http://subsonicproject.com/ (Latest one)

You can download the tool and see the SubSonic walkthrough pages.

This one is the one that i like most, because this will guide you for the ASP.Net Web Application Project in detail : http://www.wekeroad.com/sonic1.htm

I tested this northwind sample walkthrough and whoa man, I can generate the DAL classes and implement in the web page less than 5 minutes :D (see how lazy I am hohohohoho).

There's a lot of nice features in there, such as build customized query, etc. If you like to try a nice tool, I would recommend this one since it is very straight forward :)

One thing that is very important in the ORM tool is the relationship between the objects, I haven't tested on this one, but I think it should be there or else it will only be ORM without an R in the middle :P

Have fun :)

Sunday, April 22, 2007

Find application with debug set to true using WinDbg

Actually I just found out about this about always set the debug configuration to false several months ago.
At that time we were having memory problems with our servers, asp.net worker process (aspnet_wp.exe) recycles very frequently (several times / day). Because our servers have a lots of applications, probably around 100+ applications (asp legacy + asp.net), and from our team, we only manage 2 applications at the servers (and very little information about who's the owner of the other applications), we decided to ask for M... (you know who) Support Team (MST) for help.
So we collected several dump files and sent them to the MST. The first advice we received from them was to set all the debug switch to false in the web.config for all applications, and they sent the list to us. Actually at that time, I was thinking, hhhmmm... is this possible? how can this relate to the memory problem? but in the end we followed the suggestion and we modified several hundreds of web.config files in the servers :P

For more information about this debug=true setting will cause, you can find in the Scott Guthrie's Blog : http://weblogs.asp.net/scottgu/archive/2006/04/11/Don_1920_t-run-production-ASP.NET-Applications-with-debug_3D001D20_true_1D20_-enabled.aspx

When i received the list of the applications which have debug set to true, i was kind of interested how they can get this information from the dump files, whether there's a command line for this, or they already have a script to run with the dump files. So i browsed and browsed the internet about this, and gradually i know a little bit about how to get process the dump files. But very unfortunate, i was not able to find out how to get the information about debug=true at that time, until several days ago where we got another server memory problem, so i have a chance a play around with the windbg again hehehe :P

So the steps are quite easy :
1. Load the dump files with windbg
2. Load the sos.dll (.load clr10\sos.dll)
3. Execute !FindDebugTrue
Hopla, it will list all the applications with debug set to true, quite simple rite :P
you can find more help information with !help command

Note : For a memory leak problem, there's a useful tool named Debug Diagnostic Tool from Microsoft, you can find more information in here : http://blogs.msdn.com/debugdiag/

Addition at 20071010 : You can find very good information regarding to the .Net memory debugging in Tess's Blog site (http://blogs.msdn.com/tess/default.aspx)

Sunday, April 15, 2007

.Net Reflector by Lutz Roeder

Recently, I was assigned to implement and test a tool in our company.
I was given only the application output (aspx, dll, no source code), and turned out the output has also been pre-compiled, so that means we were not even able to look at the aspx (all compiled to assemblies by .net).
The purpose of the pre-compilation is mainly for performance, but it is quite useful also when u don't want the client to modify anything to the application, even to the aspx content :P
So at that time, i only have the application output and the database file (luckly they didn't encrypt the stored procedures :P)
Of course, when doing the setup and deployment to our environment, i found a lot of things which are not being covered in the document, such as "what will happen if i click on this button", etc. They were all like in a black box, which i am as a software programmer, always want to know what is the exact process flow detail, so i will be able to answer with confident if there's any question to the application.
This is the time where the Reflector becomes very handy :P
So with the great help of the reflector, i was able to see the logic of the application and find the root cause when i was stuck with the deployment.
I remembered one time several months ago, when i have a small modification which i have to make to a tool, so i was given the source code at that time. But when i finished the modification and deployed to the production, the tool was not working anymore, whereas i was quite sure that the small modification will not cause any failure to the system. So at that time, i did a dummy debug to the application, i put console.writeline every step in the code, until i found that at this certain portion of code / function, the error always happened. So i downloaded the original dll which i have backup earlier (remember, always backup!!) and then i opened the dll with reflector, searched for that part of code / function. And there i found that the code was different compared to the source code which was passed to me :( can you imagine how frustated i will be, if i didn't use this tool? So i sent the explanation to my project manager and he's ok with that since i also showed him the comparison proof that i was given not the latest source code of the tool :) so thanks so much again to Lutz Roeder's Reflector :)

You can find the tool with other very useful tool in Lutz Roeder's site : http://www.aisto.com/roeder/dotnet/

So i always have these several tools when doing the programming, such as :
1. EditPlus : very handy for editing text, regex plus syntax templates for c#, javascript, sql, etc
2. Araxis Merge : compare files and folders, very very useful especially you have several environments (development, testing / staging, production)
3. .Net Reflector : as mentioned above.
4. SnagIt : Image capture tool, very fast and handy when doing screen captures for documentation, etc

For more very useful tools when doing the programming, there are several good articles such as :
James Avery : http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/
Scott Hanselman : http://www.hanselman.com/blog/MyGrokTalkTenToolsInTenMinutes.aspx

Tuesday, March 20, 2007

HTTP & HTTPS / SSL in ASP.Net Applications

If you have the requirements to need to implement https / SSL in the asp.net application.

To avoid popup notifications for partial secured page in IE, make sure to modify references from http:// to https:// (e.g. image references, script sources, etc)

There are several way to implement the SSL in the applications, depends on the requirements :
1. Fully secured : All pages in the application will be using https://
2. Partial secured : Only certain pages in the application will be using https://, for example : login page, data submission page, reporting page, etc.

I found 2 interesting articles how to implement this partial SSL :
1. http://www.codeproject.com/useritems/switchprotocol.asp
This is a simplier solution for partial secured pages, but will need to recompile if suddenly the users need other pages to be secured :P
2. http://www.codeproject.com/aspnet/WebPageSecurity_v2.asp
This is more complete solution for partial secured pages, we can easily change the file / directory path that we need to secure in the configuration file.

PS : As you try the sample code, the session information can still be retrieved when switching from http to https vice versa.

There's a tool from microsoft called IISDiagnostic Tools, you can use the SSL Diagnostic to setup a temporary SSL certificate in your local, so you can use this to do the SSL testing locally.
http://www.microsoft.com/windowsserver2003/iis/diagnostictools/default.mspx

Friday, March 16, 2007

Stored Procedure Parameters - String limitation

In some scenario, we need to pass long string to the stored procedure.
My case is that we need to pass selected checkbox options value to the stored procedure.
Sometimes when the list of checkbox is very long, the parameter string value can exceed varchar(8000 characters).

Example of the parameter : '(''chkvalue1'',''chkvalue2'',''chkvalue3''.......)'

My solution :
1. Instead of constructing the values for the query, we change the strategy to use xml string format for the parameter.
Example of the new parameter : '<root><param value="chkvalue1" /><param value="chkvalue2" /><param value="chkvalue3" />.....</root>'
2. Change the data type for the parameter from varchar(8000) to text
3. Use OPENXML to get the values from the xml :
SELECT value
INTO ##temptable
FROM OPENXML (@idoc, '/root/param',1)
WITH (value varchar(100))
4. Use this temp table to achieve the same result

Tuesday, February 13, 2007

Proxy Cache Problem

Several days ago, we have a pre-deployment simulation problem with a 3rd party tool called FckEditor. We tried to upgrade the version of the tool to higher version.
Actually in the development, we already noticed that this tool is using cache for performance when loading the files (scripts, css files, etc), but since our local will not go to proxy, we didn't have issues with this.
But after we deployed this to the staging environment, we encountered problems that sometimes it was working and sometimes it wouldn't. I tried to remove the cache-control from the header, destroy the app domain by saving the web.config, and in the end, even IIS Reset was not working.
Finally I realized that there's a proxy cache since we're using proxy servers to access the server.
In that time, I could really simulate 3 different behaviours using 3 different proxy servers when loading the tools :(
After that, we're trying hard to find out how can we reset the proxy cache, since we don't have the ability to do this, and we also can not reset the server.
But in the end, the solution is quite simple, instead of deploying the tools in the existing version folder, just deploy the tools in a new folder and then change the configuration folder settings for the tool, so we don't have to worry anymore since the cache will be retrieved from the new folder :)

PS : this idea popped out in my mind when my friend showed me that he has no problem upgrading the FckEditor at his local, he was renaming the folder name between FckEditor versions to show that it was working.

Saturday, February 3, 2007

ASP.Net - Export to Excel - Unicode characters are not being displayed correctly

I found this problem when exporting datagrid to excel using .Net Response object.
Quite strange actually, we have no problem in our local (WinXP), but when we deploy to the Server (Win2K), the excel result is not displaying the unicode characters correctly.
It can work after we tried to open the excel result using notepad and then saved it with unicode encoding, notice that previously when we first open the document in excel, the font is Arial, but after saving the file with the encoding, it is using Arial Unicode MS.
After several hours, testing this and that, in the end i found an article for exporting datagrid to excel in CodeProject.
And the reply post in the link just resolved my problem.

Illustration :
When exporting the datagrid to excel, actually all of the things are still in html elements (can try to open the excel file using notepad / text editor). So the content will be <table><tr>.....</tr></table>.

I thought that this encoding problem can be resolved by trying to modify the charset and contentencoding in the response object. But i was wrong :(
From the reply post above, you can see that actually it is very simple thing, just add a head element with

<meta http-equiv=Content-Type content="text/html; charset=utf-8">

before rendering the datagrid.
This way, the output can be intepreted correctly, and the unicode can be displayed correctly.

Korean (Unicode) ASP Application Migration

These are the things that my Team discovered when we did the migration for Korean Application from Korean Server Based System to English Server:
1. Database objects
If the tables are already using nvarchar / nchar as the field type, there should not be a problem.
But if the fields which contain korean characters are using varchar / char with korean collation, we will need to modify the field type into nvarchar / nchar.
And after changing the field type, all insert / update to these fields will have to have 'N' before the string, for example : N'This is the string'
The modification can be :
- in the code
- in the stored procedures (parameters)
2. Language Packs
The server may need to be installed with the korean language packs
3. Sending Email
The application has a tool to send out emails. There's a feature to encode the from name, subject, and body using certain charset, euc-kr is a standard charset that we are using for Korean Application.
4. ASP Application
To display the information correctly in the korean characters, we may need to set the <%@ CODEPAGE=949 %> in the top of the page.
Previously we're using the Session.CodePage=949 but still don't know why it's not working after we move the application to our server, but we tried using Session.CodePage=CP949 and it worked.
Because CODEPAGE=949 is documented in the msdn articles and Session.CodePage=CP949 is not, we decided to just use the CODEPAGE.

Introduction & Background

Hi All,

Actually I want to do this quite a long time ago, because in these years being as a developer, I experienced a lot of difficulties and dead ends that I could not resolve.
But in the end, many thanks to the internet and all the people who have submitted their experiences to the web, I was able to resolve many of them :)
And also many thanks to the people who have helped and guided me in these years, you are all the greatest teachers that i have :D
So hopefully, my posts will be able to help you all, so you don't have to waste hours late in the office like me before :P

A little bit of my background :
I'm actually not from a technical background degree, in fact, i'm from economic degree, but don't ask me anything about it :P
After i finished the final university exam, i worked as a technical support for a several monts, assemblying and disassemblying computer parts, hhhmm... wonder where this part should be :P
After the graduation, got interviewed by several IT companies, kind of hard coz' i'm not from IT background, but in the end, I joined a software house company. They are handling Health Information System. I joined the company in a quite good timing, because they were migrating the previous application from FoxPro to .Net (VB.Net). So this really built my base for .Net knowledges and I have a lot tutors and great colleagues along the way there :)
After 2 years, i moved on to another company, this time it is a mining company and quite isolated, but in the environment, i found a lot of new things here, from doing Macro Excel Reporting, COM+, C#, Web Services, Window Services, Console Applications, Replication Engine, Batch Engine, Scheduler Engine, .Net Interopability with COM+, Enterprise Services, BizTalk Engine, Windows Server 2003, etc. But in the end, it is the great people there who gave and share the knowledges to me :)
After finished my contract, I decided to try my luck abroad and now I'm in a technology company and handling their marketing site. Quite interesting for me, since the application is being used accross the asia pacific japan region, so a lot of customers to handle and to communicate with along the way :)