Interview Questions Headline Animator

Wednesday, November 26, 2008

SQL Server Compact Edition / Entity Framework bug

I am working on this really smart, smart client application installer. Which smartly installs other pieces of another smart client application as and when required.

It makes sure that only those bits are downloaded that are not already installed. So it takes care of upgrades on its own. So basically we are writing our own "ClickOnce" functionality.
Why are we not using ClickOnce out of the box? Well that would require another post, but let's say we require much more granularity than what "ClickOnce" provides us, on this "Installation Manager", and put it at that.

Anyways, I am doing some book keeping using SQL Server CE on the client machine to maintain account of upgrades and installations. For this I am querying the SQL Server CE database and in the process and I encounter an error that says:

"The ntext and image data types cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses, except when these data types are used with the LIKE or IS NULL predicates."

I am not even working on ntext data type. The select query goes something like this:

IQueryable files = entities.FileInfo.Where(fileInfo => fileInfo.FileName.Equals(fileName));

And "FileName" is not an ntext datatype in the entity "fileInfo". It is an nvarchar.
Interestingly, if you fire the same query on the Management Studio (SQL Version of the query of course), it works fine. It only breaks when you use LINQ to SQL or EF.

After a little research I find out that there is a bug in SQL Server 3.5 RTM which was incidentally not resolved even in the "SQL Server Compact 3.5 SP1 English". And later there was an out of the bag release that was made to resolve this issue. So the Hotfix, cannot be installed directly. You need to uninstall "Microsoft SQL Server Compact 3.5 SP1 English" from Add Remove Programs before you install this hotfix.

Once the Hotfix is installed, your query will just work...!

In case if you are wondering whether you need to re-install "Microsoft SQL Server Compact 3.5 SP1 English"? Well, installing it back will remove the hotfix. So DO NOT DO THAT.

Sunday, November 23, 2008

Best RSS Feed Reader

My wife is a writer, and a pretty good one for that matter. Recently she went for a job interview, where she was asked a lot of questions about current affairs, and she doesn't exactly read the news regularly. So I told her she should. But she doesn't like reading the news paper, and I told her about online news. About RSS Feeds and Feed Readers.

So which feed reader do you use. Of course every developer uses one. So what else does a developer use? Internet Explorer and Microsoft Outlook. Post Internet Explorer 7, you can subscribe to RSS Feeds using IE. you can read the posts online on IE. But the beautiful thing is every time you subscribe to a feed on IE, it nicely goes and adds itself on the RSS Feeds folder in Microsoft Outlook. This gives you the offline reading facility of course it also depends on what you are subscribing to. Some of the stuff is just not available offline. Like MSDN Magazine, which just has a one liner and a link to the actual article.

Speaking of which, MSDN Magazine is available online since January 2008. The MSDN Magazine is a fantastic read and is on top of my reading list every month. Some of the articles are just too good. Like for instance, this month my favorites are: The editor's note (which is always a pleasure to read), Thread Management in the CLR, Design for testability, Static Analysis tools for .Net.

Other favorites on my feed reader are:

  1. Ann-Dee's Tic-Tacs (My wife's weblog)
  2. Stack Overflow
  3. Threads watched by Channel 9 Team
  4. Business Week Online - Tech Beat

Wednesday, November 19, 2008

Downloading and installing AdventureWorks Database

I am assuming that you want to write a prototype of some sort for which you want a sample database to work with. And I am assuming that you don't have AdventureWorks on your machine. Putting down quick set of steps:

  1. Go to http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004
  2. Click on AdventureWorksDB.mdi, in case you are looking for the AdventureWorks Database for SQL Server 2005. there are also other sample databases available. This post is specifically for the AdventureWorks database for SQL Server 2005
  3. Accept the Agreement
  4. Download and run the installable.
  5. Open Visual Studio Command Prompt.
  6. Type in SQLCMD and press enter
  7. Type in the command
    "exec sp_attach_db @dbname=N'AdventureWorks', @filename1=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf', @filename2=N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_log.ldf'"



  8. Please note that the Drive could be either C:\ or D:\ depending upon where you have installed the AdventureWorks Database MSI.



 



This will attach the AdventureWorks database. Fire up SQL Server Management Studio and confirm whether Adventure Works exists or not.

Saturday, November 15, 2008

The Sleeping Giant...

I am going to talk about the experience that I went through recently, when I met with a quite dangerous accident. It could have been quite fatal, fortunately, it wasn't. This post is going to be starting from around 2 seconds before I met with the accident to about 5 minutes after the accident. photo

on the 14th of November 2008, around 11.45 AM, I was going to work on my motorcycle. You see there are these lorries that haul huge stones from the stone quarries to wherever they take them, and the lorry drivers are very careless. They never abide the traffic rules. One such lorry driver was driving on the opposite direction and he suddenly decided that he needs to take a 'U' turn, and he did, just 10 or so meters ahead of me. I was driving around 80 Kilometers an hour and didn't have enough reaction time. I applied both the brakes simultaneously, bringing the bike down to around 60 kilometers an hour, and had a head on collision with the lorry. The bikes front went under the lorry I collided with the lorry head on. This is what happened.

The things that went through my mind during those 2 seconds before the collision and 5 minutes after, were quite profound. Now that I reflect upon it, it tells me about the stupendous processing power of the brain, when it is under stress. If only we could channel this power in a productive way. There were important things, and then the silliest things too. I cannot remember the exact sequence of things that my brain ran through, but I will try to list them down, at least as many as I remember (of course I don't remember everything).

So first when I see the lorry coming in, I think.

photo1"What's this guy doing? Is he crazy?"

"Should I just brake or should I turn left? Oh but there is this car and a bike on my left, I can't turn."

"Good I have disk brakes in the front. I won't fall and go under"

"Thank God I am wearing a helmet. I think it should be able to reduce the impact"

"Should I consider turning right?"

"I can't see what's coming from the opposite side."

"Dang... the driver is getting off to run already...!!!"

So that's when I realize that nothing can be done and that the collision is going to happen at a very high speed. That's when I give up and think,

"This month the finances were already down... How am I going to repair the bike..."

"My bike is not registered in Hyderabad. If I launch a complaint with the police, they will confiscate the bike and I would have to pay the road tax to get my bike back."

"I hope my laptop doesn't break, I will have to wait 2 or 3 weeks to get a new one. And I have my external hard drive in the bag. All the data is in it."

"I don't want to be perennially injured. Dang... that would be bad."

"I just got married I have to save myself."

"I had to finish the Click Once API Prototype today. Gone...!!!"

"Shit...! I wish I hadn't sold my car...!"

Now the collision happens...!!! And this is the most interesting part... the bike collides, I fall off and after that the bike goes under. Since the driver has already jumped off the lorry before the collision and run, the lorry slowly climbs over my bike and crushes it. The pictures are after the lorry climbs over the bike. Now the collision was at, at least 60 kilometers an hour so it is hard. I have hit the lorry with my head and chest. You can't imagine the power of the impact. After I fall off, the first thing I do, instinctively is get up. On standing up, I realize that I can't breathe. I feel my lungs are pushed deep into my chest and it pains when I laboriously try to pull in dear oxygen. It takes me around 7 to 10 breaths to pull in oxygen and get my breathing back to normal. During this time my head is going bonkers.

"My wife is going to really scream at me. I better not tell her before I reach home."

"Nothing is going to happen to me. I belong to the demonic tribes of Banasur, Narakasur and Babrubahan. And they were wicked difficult to kill."

"Heck I have been pushing weights in the gym for over 15 years now. This impact isn't going to do me nothing."

"I have to start breathing and then turn around and look at my bike. I have to analyze the damage and the expense this is going to cause me."

"Dang... I tore my jeans... Will have to buy a new one..."

"Oh but the oxygen first... breathe... breathe..."photo2

About 10 seconds later I breathe normally, turn around and look at my bike... I am standing on my legs, firm and strong. I can feel pain in my chest, my shoulder and my right upper thigh, very very close to my genitals. Heck I  just got married, I have to think about everything. I press my chest and see if I feel any sting, to find out if there are any bones broken. Nothing broken. I turn my neck around and check for my spine. No pain there. I take a little jab at my groin. The skin burns, but no internal pain... thankfully. All this time my 10 kg heavy laptop bag is on my back. I offload it carefully. People have started gathering all around me. I cannot see my bike any more because of the crowd. Someone gets me water and 3 people are asking me to sit down on a rock nearby. One local fellow with black clothes on comes to me and gives me an IPhone. He says some "Reddy" wants to talk to me. I take the phone and find out it is Koti. He asks me how I am. dang...! it wasn't more than a minute or perhaps a minute and a half after the collision. How did he find out? I see Pavan from the mailroom. He takes control of the situation. He calls the Ambulance, the police, and picks up my laptop bag. While all this is happening, I am thinking.

"How do I take out my bike before the police arrives?"

"I don't want the police to confiscate my bike."

"I don't think I have the strength to pull my bike out from under the lorry."

"I have to go home to my wife before she comes to know about this whole thing from someone else."

"But I can't leave the bike here. I have to get out of here with the bike."

"Nothing has happened to my hands. I think I will be able to code from home."

"Thank God Ma isn't here. She would have gotten awfully worried looking at me limp."

"Where's my phone? I hope my phone isn't broken."

That's when a guy comes to me and gives me my phone. And I am relieved to see that it isn't broken. Pavan tells me that he will take care of the bike. I get on to the ambulance and they suggest I go to Apollo Hospital and do at the checks.

At Apollo, all the checks are done later and I find out that no bones are broken, and that my diaphragm and liver, which were just under the point of impact are fine. The doctor tells me that I am a strong man and my gym workouts saved me. My friends Vikas and Rajesh come over to the hospital and take me home later in the evening.