Aug 10 2008

Connect MySql with .Net


Recently I started working on a new project and the clients wanted to use MySql database server because it is free. I had dealt with the MS Sql 2000 and 2005 servers from .Net and that was a breeze. I had a hell of a time trying to figure out how I can connect MySql and .Net and finally after lots and lots of googling and with lots of common sense I managed to get this done. So I thought of writing this post to help all those who have this requirement and don’t want to go through the entire WWW to find this out. 🙂

Step 1
First of all you must download and install the connector that is needed to connect with the MySql database. You can get the driver here free of charge. (It’s open source ;)) At the time of writing version 5.0 was the stable and newest version. Get that and not 1.0 because to install 1.0 you need the .Net framework 1.1.

Step 2
Then go tour project in Visual Studio. (I am using Visual Studio Professional 2005) Right click your project and select Add Reference, and select MySQL.Data as shown in the figure below.

Step 3
Now you are ready to go. Everything is set and hopefully will work out. 🙂 Just type some code like below to check whether everything is in order. (I am using an ASP.Net page to check connectivity)

public void Page_Load(Object sender, EventArgs e)
{
string conString = “SERVER=localhost;DATABASE=Infinity;UID=root;PASSWORD=test123;”;
MySqlConnection connection = new MySqlConnection(conString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = “select * from Room”;
connection.Open();

MySqlDataReader Reader;
Reader = command.ExecuteReader();
while (Reader.Read())
{
string row = “”;
for (int i = 0; i < Reader.FieldCount; i++)
{
row += Reader.GetValue(i).ToString() + “,”;
}
Response.Write(row);
}
connection.Close();
}

If everything works fine your aspx page should show all the data of the table you queried.


Aug 9 2008

A Forced Vacation


Universities in Sri Lanka have this strange habit of being closed down while in the middle of the academic year due to various reasons. University of Moratuwa was closed down last Thursday (6th August) because of a student clash that took place at the hostels on the 5th of August.

The university premises are out of bounds for us at the moment and the date of reopening has not been declared yet. I guess it won’t be closed for more than a week and normal academic work will start again in the coming week.

However as this is sort of a vacation for us students, I plan to finish off the assignments that are due in the coming weeks and most importantly watch plenty of movies. I have a huge collection which I downloaded recently and had no time to watch any of them during the past couple of weeks.

I hope that uni will reopen soon because it’s great to be with friends than being stuck at home all alone.


Aug 8 2008

Speak Olympiad 2008


University of Moratuwa is proud to house an energetic Gavel Club which is affiliated to the Toastmasters International. This club is dedicated in improving the speaking and presentation skills of university students with the noble motive of producing excellent public speakers who can go in front of any audience and speak their hearts out.

Gavel club annually organises a speech contest in which any student of the university can take part. The competition is called Speak Olympiad and it is one of the most wonderful events in the university calendar. When this year’s competition was announced 50% of me wanted to participate, and the remaining 50% was reluctant because of the high preparation needed and not being a member of the Gavel club, I wondered whether I can even go into the 2nd round.

Finally I decided to take part and chose the topic “Pillars of My Life” in which I talked about three life values; Identifying your strengths and weaknesses, Prioritizing life and Grabbing the first opportunity, while giving real life experiences to support the facts. The competition was held in three rounds and I got selected to the finals.

All the finalists were really great speakers and the finals of the SO 2008 was a delightful event. The judges who were famous toastmasters of the country praised the efforts of each and every speaker. I got ranked as the first runner up and that day was one of the most happiest days of my life. The only thing that I had to regret was not being a member of the Gavel club. I felt that if I was a member I could have done something more and I could have been a better speaker. Anyway I am really happy that I took part and I hope and wish that the Gavel club will hold this event in each and every year that is yet to come.

Before I end this post I think it would be nice if I thank few people who were behind my victory.

Dilini, who is the President of the Gavel Club and one of my closest friends at uni. She is the one who pushed me to participate, helped me select a topic for the speech, proof read and corrected my speech, gave feedback after listening to my speech, and encouraged me until the very end. So thanks a lot Dili.

Next another of my closest friends and member of the Gavel club, Nuwanpriya. He also helped me to get my speech prepared, gave me feedback after listening and helped me to get through the impromptu speech sessions. I couldn’t have done it without you bro. Many thanks to you!!

I would also like to thank all the members of the Gavel club specially Aravinda, Bodul, Erangi, Lakshitha and Dulini for all their efforts and encouraging words.

Finally I would like to thank all of my friends who came to the watch me speak and encourage me all the way. Thanks a lot you guys and gals! 🙂

P.S.
This post should have appeared a long time a go. SO 2008 was held in the first three weeks of June. I am very sorry for being lazy and delaying this post… 🙂


Aug 2 2008

Playing Topspin Vs. Losing Guts


Tennis has always being a favourite past time of mine since I was very small. Those days when I went for my regular coaching classes on Sundays I remember how my coach emphasized the point that we should play flat shots instead of spinning the ball. The handshaking grip was used to grip the racket thus giving no chance of brushing the ball to make it spin. This was back in the years of 1994 and things have highly changed now.

I am a member of the University of Moratuwa Tennis team and we have a very experienced coach helping us. One of the very first things he changed in my way of playing is how I played the forehand shot. He asked me to change my grip and brush the ball instead of playing flat.

Brushing the ball and playing topspin certainly have a bunch of advantages. Most often the tendency of hitting the ball out of the court is reduced. Secondly the ball bounces very high when it lands on the ground. Finally you have more control over the shots that you play.

Nothing comes for free in this world and the same goes for playing topspin. The main problem is the frequency of broken guts. As the ball is brushed when the shot is played, the guts of the racket rub against one another and they tend to break very quickly. I have been playing flat shots for many years and not a single string broke in any of the rackets that I have played with. However I switched to playing topspin not very long ago (one or two months back) and today at practices for the very first time in my life a string broke.

The topspin shot involves more wrist work as well and I am catching up the shot these days. I will continue to use this instead of playing flat which is the old fashion of playing. As for breaking guts… I’ll have to live with it I guess. As I mentioned earlier, nothing comes for free in this cruel world!!!! 🙂


Jun 30 2008

My Second Traffic Ticket…


I got late to go to campus today for my daily lectures and had to speed up a little bit to make up for the lost time. When I was on the Panadura bridge, a jeep was traveling before me and he was moving like a tortoise. The jeep was barely driving at 40 km/h I guess and I had to overtake it inspite of the double lines that stretched along the bridge. After a careful maneuver I overtook it and lo and behold a cop appears and asks me to stop.

I tried to put on an innocent face and told lots of stories including “I’m still a student, Late for lectures” etc etc, but the cop didn’t budge. He wrote me a ticket and asked me to come to the police station to collect the license. The real story begins from there.

When I got to the police station, I found that I have to collect the actual ticket from there, go to the post office and pay the fine, and then finally come back to the police station to collect the license. The fine was 500/=, but I guess I burned petrol worth more than that just for the trips between the police station and the post office. Anyway, I was in the wrong and can’t blame anyone else. Must be more careful next time…..


Jun 8 2008

Breaking into a Maruti… Step by step istructions :)


Yesterday my uncle came to visit us. When he was about to leave he couldn’t find his car key anywhere. Finally he saw that he had locked it inside the car. The mission to open the lock begins from there. 🙂

First of all my uncle popped out the beading which runs along side the shutter. After this was removed we could see the metal rod of the lock. Then I took a a bicycle spoke and bent the end to make a little hook. Through the gap which was created by removing the beading, I saw that the rod curved slightly before going into the depths of the door. So I inserted the spoke through the gap and caught the curved placed of the rod with the hook and pulled it upwards. The lock jumped up instantly. 🙂

That’s how I broke into the Maruti. Guess I can find a job at Darley road in Colombo even if I don’t graduate from uni. 😀


Jun 4 2008

Untraceable


Last Sunday I had nothing to do in the evening which made me decide to watch a movie. I went through the list of movies that I downloaded recently and thought of watching ‘Untraceable’ because it had good rankings in the imdb chart.

The movie is about a killer who goes on killing innocent people randomly (so it seems at the beginning) and the killings are broadcast live over the internet through his own web site. Two cyber crime fighters of the FBI are working very hard to track the killer, but their efforts are in vain because the killer really knows what he’s doing.

That is how the story goes and it is a real thriller indeed. I loved the movie from the start, but I felt that the ending could have been more ‘puffy’. If you asks me, the movie ends too abruptly. Untraceable is directed by Gregory Hoblit. Diane Lane, Billy Burke, Colin Hanks and Joseph Cross give life to the main characters of the movie.


Jun 1 2008

Hit The Grounds 2008


Hit The Grounds 2008, the annual cricket carnival organised by the Computer Science and Engineering Society (CS&ES) of the Department of Computer Science and Engineering, University of Moratuwa, Sri Lanka, was held for the 5th time on the 24th of May. Teams from many leading IT firms, undergraduate teams and a team from the staff participated in this event.

I was one of the event managers and had a ball of a time organising this event with Shanaka (the other event manager). Zone 24×7 came forward to sponsor the event.

We had a spot of trouble from the MIT team because they refused to play on the pitch that was allocated to them and the team from Batch 05, to play the quarter finals. In that particular pitch bowlers didn’t bowl from either side because the boundary lines overlapped with another. As a result the pitch was in favour to the left handed batsmen. MIT refused this pitch because most of their batsmen were right handed. They wanted to use both sides of the pitch. However rules are rules and me along with the rest of the organising committee didn’t allow MIT to go ahead with their request. So after fussing for more than 45 minutes they agreed to play and the match went underway. MIT went on to score 100+ runs in just 7 overs in the pitch they said that was not suitable for their batsmen 😛 This huge delay prevented the finals from being played and MIT and WS02 went home as joint winners.

The best batsman was from MIT and the man of the series and woman of the series awards went to WS02. Zone 24×7 bagged the best bowler award. As I ran around the ground carrying a Zone 24×7 banner, I was awarded the best entertainer award. 🙂

The event was major fun for all who participated and I can’t wait for Hit The Grounds 2009 to take place.

(Photos of the event are available here)


Jun 1 2008

My Very First Traffic Ticket..

Yesterday me and my family went to Ahangama (A small town which is a about 10km from Galle) to participate in an alms giving and I played the role of the driver. It is a very famous fact that the galle road is flooded with traffic cops almost everyday, and I took great care to avoid doing all the ‘bad things’ while driving 🙂

As we were just passing Galle, I was stopped by a cop who jumped to the road from behind a well hidden Coconut tree. I stopped the car and tried to think of what I did wrong. My father also got down and the both of us went to have a chat with the cops. When I asked them what my wrong doing was they said I drove beyond the speed limit. It seems that the limit was 56km/h and I have been driving at 61km/h. Can you believe it?? Being stopped for driving at 61km/h??

Then this guy asks me to come to Galle to collect my license during the coming week. I half begged him to let me go because I have lectures all week and a trip to Galle would surely take half of the day (Excluding the official stuff that will have to take place at the Police station). After showing him my university ID he wrote a small ticket for 500/= that read “Overtaking in a wrong manner” instead of speeding which costs 1000/= and asked me to pay the money to the Galle post office. So I turned the car around, went back to the Galle post office, payed the fine and finally came back to the place where the cops were and collected my driving license. Finally I was on my way home and I took care not to drive too fast and collect my second ticket for the day (and for my driving career)… 🙂


May 20 2008

Using the Struts Framework for Validations

As I mentioned in one of my earlier posts, I started learning about Struts last week. Today I had to do some validations in the forms of the jsp pages and the first option that came to my mind was to use javascripts. However the people for whom I am doing this project, asked me to use the Struts framework instead. So after a healthy breakfast I set to get things done and opened google and typed “validations using struts”. 🙂

After a couple of hours and some common sense later, 🙂 I rigged up an application that used the struts framework for validations. I didn’t find one single tutorial that provided the basics. So I thought of combining what I got from many of them and put it here so that someone else like me can use this article to get the concept of validations under the belt and thank me whole heartedly. 😀

Well to start off with you need the jsp. The code below is of a sample jsp page.

The “s:head/” tag is quite important. It took me quite some time to understand the importance of it because I couldn’t get anything to work without that tiny little tag.

The next thing is the validations xml file. The struts framework uses xml files to do the validations. For each jsp there is an action class which handles the related business logic. An xml file should be created at the same location of the action class bearing the name action class name-validation.xml. For example if your action class’ name is SignInAction.java then your xml file should be named SignInAction-validation.xml. The code for the xml file is given below.

In the xml file the field-validator type is used to inform the struts framework what type of validations are required. For example if you put “email” there, the framework will check whether the entered email address is a valid one.

So that’s all folks. When you run the application try submitting the form without entering anything in the text boxes. The validations should pop up instantly. 🙂 Good luck!!!