C# 2.0 Yield Statement, You will like it.

If you are a new to c# development and just started learning c# or even started with version 2 of the language, propabilities are high that you know what Yield statement is. The same propabilities are there if you are a real geek who enjoys the taste of new technologies in their Beta versions. If you are like me and started c# about 5 or 6 years ago with its first version and find work situations forces you in direction you haven’t expected or planned for, you may find this statement new and yet lovely.

Well, from time to time I give myself a break to get some of this rapidly growing language, after all C# 4 is on doors. As I was reading about some of c# features that I couldn’t get a chance to use I found the Yield Statement.

Yield statement allows you to return Items from an enumerator while keeping its state. In other terms if you have a method that returns an Enumerator of certain object you can call that method several times each time the method starting where it was stopped. You can think of it as  a static variable or even a cursor for Enumerators. K don’t go away, I know you are just like me and need an example so let’s see.

There is more, lets continue…

Bookmark and Share

Posted by Bassem on April 27th, 2009 under Development • 4 Comments

My worst weekend ever

It was a 2 days weekend plus 2 days vacation. A sum of 4 days make you put a plan of either Business Or  pleasure. For me it was a one day of fun and 3 of study. well I had the fun part and that’s good. For the study part, It never happened. I got my Laptop and PC broken in the same day. what made it worse is that I mistakenly formatted All my Laptop hard drives, yup I couldn’t believe it myself as well and it was a shock. you know the rest, I spent my days trying fixing my PC which still dead and installing everything on my laptop. I still somehow see it as an Evil Eye so take care every body :D .

Some of you may think why I would write this stupid post, come on I have to share my misery with you not only my knowledge plus It’s my Blog and I can write whatever I want :D .

Bookmark and Share

Posted by Bassem on April 20th, 2009 under Personal • No Comments

Friday Tip 04, Behind Asp.net Sqlserver sesssions

ASP.Net developers have been using sessions for state management since asp.net released and on a daily bases in their applications. However most developers use sessions as its default mode moreover others don’t know about these modes at all. Today I’ll recap the different types of session states and discuss in details one important type “Sqlserver sessions” that would be necessary to know about when working on big applications that require web farm deployment.

Asp.net session state modes:

1- Inproc (default)

2- Out Of Proc / State Server

3- SqlServer

session states can be configured from web.config under sessionstate node as follows
<system.web>
<sessionState mode=”InProc”>
</sessionState>
</system.web>

There is more, lets continue…

Bookmark and Share

Posted by Bassem on April 18th, 2009 under Friday Tip • 4 Comments

Friday Tip 03, OLEDB Provider against sqlserver database, A tiny worthy Tip.

This is not precisely Friday nevertheless I’m writing my Friday Tip which I couldn’t do yesterday. For me Late is better than never, for you who were waiting , If any, my apology.

Back to our today tip, As you all may know we can use an OLEDB data provider to connect to sql server although the preferred and more efficient way is using a sqlserver data provider which we all in 2009 do, I guess. However if you haven’t got a chance to work with an old developed application for maintainance, solving bugs or even adding a new functionality as I had let me tell you some people used to use an OLEDB with sqlserver. No they were not idiots since one reason for doing that is creating one Data Access Layer that can work with diffrent data sources say sqlserver and Access.

Anyway our Tip is as follows when using an OLEDB data provider with sqlserver you would have to make sure that you add the sql parameters in the same order they appear in your stored procedure when calling it from your .net application.

Why is that ? BECAUSE OLEDBs use what is known as parametrized queries which use parameters order rather than their names as opposed to stored procedures.

Now believe me when I say the lack of this simple tip can cost some developers hours solving a simple bug in an old application as they will find no reasonable cause for the failure from their own point of view off course and .net won’t aid them with any descriptive error message.

For me It took about 10 mintues 2 years ago when I faced that situation, see one tiny tip can save you hours.

Bookmark and Share

Posted by Bassem on April 11th, 2009 under Friday Tip • No Comments

IIS 6 Problem,uuh, and confusing error message

Last night a colleague was trying to setup a new website on a new server. A 5 minutes job, Right? Yup but It wasn’t. As we all now creating a new website on IIS is as easy as few known steps. However what he got was unexpected. After finishing the setup he tried to browse the site which always returned this page can’t be displayed page. As you may think he though it’s an IIS problem. well, he did everything you may have to think of including, restarting IIS, Checking IIS configuration, the right .net framework installed, … etc. Any way he called me to figure a solution together. Our first step then was to check the windows event viewer which keeps track of all system and applications errors. To be honest, what we got from the error text in the event viewer was much confusing than an aid. Here is the error message in the event viewer

Faulting application w3wp.exe, version 6.0.3790.3959, stamp 45d6968e, faulting module kernel32.dll, version 5.2.3790.4062, stamp 46264680, debug? 0, fault address 0×0000bee7.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

for the first while you would think that it’s something related to the .netframework or even windows installation. After several trials and googling we got nothing. well I tried to think out of the box and ignore that error message. knowing that the website we were installing is back ended on sqlserver, I turned my eyes to sqlserver and guess what, It was the right direction to look at.

I figured that the NETWORKSERVICE builtin IIS account lacked the required permissions on the database and the solution was quite simple as giving it these permissions.

well Although The problem solved I still don’t know why didn’t I get the friendly CRASH YELLOW PAGE  :D instead of this ambiguous error.

If you didn’t get much knowledge from this article, it would be a great lesson to learn how to expect the unexpected and to remember that some solutions may be very well not reasonable when you think traditionally.

That’s it for today, Got to go to work.

Bookmark and Share

Posted by Bassem on April 8th, 2009 under Development • No Comments