What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Monday, May 08, 2006

In the previous version of asp.net, v1.1, the CustomValidator did NOT run when the control(e.g TextBox) was empty. Possible solutions were to create your own control (something like RequiredCustomValidator : CustomValidator) or the change WebUIValidation.js file so it will actually validate the control even if it's empty. Now, in the new version, v2.0, you can simply set the ValidateEmptyText to true and you're done. Nice (and useful) !

Posted by Oren Ellenbogen 
08/05/2006 04:02, Israel time UTC+03:00,     Comments [2]  | 
# Friday, May 05, 2006

I know, this is kind of a childish post but heck, It's hilarious to hear someone tries to pronounce my name - kudos Chuck, you did it !!

Click here to download the podcast (btw - my "thing" starts at -5:38).

Thanks Chuck, I'll update my progress on this one so keep reading ;)

Posted by Oren Ellenbogen 
05/05/2006 07:19, Israel time UTC+03:00,     Comments [3]  | 

The using keyword works on objects that implement IDisposable interface (an interface with one member, the Dispose() method).
So a code like this:

using (SqlConnection conn = new SqlConnection("connection_string"))
{
    // use conn...
}

Is actually transformed into:

SqlConnection conn = null;
try
{
    conn = new SqlConnection("connection_string");
}
finally
{
    if (conn!=null)
        conn.Dispose();
}

The using keyword allows more elegant writing, nothing more actually.

The additional feature I would like to see is that in case of exception, a method in the implementor of IDisposable will be called, meaning the code should(?) be transformed into something like this:

SqlConnection conn = null;
try
{
    conn = new SqlConnection("connection_string");
}
catch(Exception err) // *
{
    HandleException(err);
}
finally
{
    if (conn!=null)
        conn.Dispose();
}


Of course, I would have to implement HandleException(Exception e) method as part of implementing IDisposable interface.

Why is this good for ??

Well, think about creating a transaction scope interface:

interface ITransactionScope : IDisposable
{
    void Commit();
    void Rollback();
    // ....
}

In this scenario, it would be great that if no exceptions were thrown, the transaction should Commit() by default,
but if any exception was thrown and not handled - do Rollback().

using (ITransactionScope trans = DbServices.StartTransactionScope())
{

    // delete 1

} // should do Commit()


using (ITransactionScope trans = DbServices.StartTransactionScope())
{
    
    // delete 1
    
    throw new ArgumentException("just to make the point clear");

} // should do Rollback()


HandleException(Exception e) will allow me to set a flag for Rollback on Dispose or to Rollback immediately; This can be quite handy.

Today I Rollback at the Dispose(if the transaction state is "uncommitted") and I force my programmers to call Commit() method directly.

* I know that catching Exception is a bad practice by default, but in those scenarios I would rather ask the "is\as" question(s) and handle my exception than wrapping using with try-catch blocks. After all, using should allow elegant code...

What do you think ?

update:
I've posted a ladybug at Microsoft Product Feedback, you can check it out (and vote!!!) here:

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=f3c7e216-8790-4937-acc0-502848232a9d

Posted by Oren Ellenbogen 
05/05/2006 10:37, Israel time UTC+03:00,     Comments [2]  | 
# Tuesday, May 02, 2006

I have a popup window(calendar control) which contains a drop-down-list with many items in it. The problem occurs when I try to select the year 1930, which is outside of the popup frame:

 

calendarbug.gif

 

This close the the entire popup window instead of selecting the year 1930 as expected (well, I did anyway). I tried to cancel the event from bubbling, to set the height of the select object (doesn't work), you name it !

*btw*: I don't want to change the entire flow or to work with a different window model - to much work.

Any ideas ??

Posted by Oren Ellenbogen 
02/05/2006 03:24, Israel time UTC+03:00,     Comments [1]  | 

My team use the Sql Server 2005 Replication feature in order to synchronize between databases in different enviornments. One of the strange things though, is that the reference to Microsoft.SqlServer.Replication generated a weird "Invalid access to memory location. (Exception from HRESULT: 0x800703E6)" Error. After a quick google search I found this link which offers a nice workaround (this seems to be VS.NET 2005 bug) which worked for several folks out there but unfortunately it didn't work for me. The search continues...

Posted by Oren Ellenbogen 
02/05/2006 09:32, Israel time UTC+03:00,     Comments [4]  | 
# Wednesday, April 26, 2006

In one of our screens we were required to refresh a Modal Dialog window in order to redraw the entire screen. Trying to refresh a Modal Dialog window will resolve in a new window with the same url.

A possible solution is to create a new "container" file (MyContainer.aspx) which will only have an IFrame with the "real" page(MyPage.aspx) in it as src; Your main page (MyMainPage.aspx) will open the "container" as Modal Dialog instead of the "real" page. The trick is that the IFrame can refresh itself so we've created a Modal Dialog which behaves as a normal window. if you need to set the Modal Dialog returnValue parameter you can call "top.returnValue=...." from the "real" page.

The downside of this solution is QueryString delegation - if you need to send a QueryString parameter(s) to your "real" page you will now have to pass it via the "container" file.

Posted by Oren Ellenbogen 
26/04/2006 05:16, Israel time UTC+03:00,     Comments [6]  | 
# Tuesday, April 25, 2006

This is one of the strangest things I've seen lately, but it turns out that sending "2006-04-25 14:15:26:421" (via SqlParameter from SqlDbType.DateTime) to my Sql Server 2005 database has been saved as "2006-04-25 14:15:26:423". Does it happen every time you might ask? well, the sad answer is NO; Sometimes(really, just sometimes) it happen and sometimes it don't.

Why do I need such accuracy? Well, this DateTime column is one of the Primary Keys in my table. Trying to pull out "2006-04-25 14:15:26:421" will give me... nothing !

I wanted to reproduce it on a clean sheet so I created a new table named "CreationDates" with the single column "CreationDate" which is from DateTime type of course.

Then I've written the following code:

class Program
{
   static void Main(string[] args)
   {
      Init();
      Test();
   }

   private static void Init()
   {
      // Default culture - hebrew (I need it this way).
      CultureInfo israel = new CultureInfo("he-il");
      israel.DateTimeFormat.LongTimePattern = "HH:mm:ss.fff";

      Thread.CurrentThread.CurrentCulture = israel;
      Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
   }

   private static void Test()
   {
      string connString = @"MyConnectionString";
      using (SqlConnection conn = new SqlConnection(connString))
      {
         string query = "INSERT INTO CreationDates(CreationDate)VALUES(@CreationDate)";
         SqlCommand cmd = new SqlCommand(query, conn);

         DateTime dt = DateTime.Now;

         SqlParameter p1 = new SqlParameter("CreationDate", SqlDbType.DateTime);
         p1.Value = dt;
         cmd.Parameters.Add(p1);

         Console.WriteLine("parameter time: " + ((DateTime)p1.Value).ToString());

         conn.Open();

         cmd.ExecuteNonQuery();
      }

      using (SqlConnection conn = new SqlConnection(connString))
      {
         string sQuery = "SELECT TOP(1) CreationDate FROM CreationDates ORDER BY CreationDate DESC";
         SqlCommand sCmd = new SqlCommand(sQuery, conn);

         conn.Open();
         SqlDataReader reader = sCmd.ExecuteReader();
         if (reader.Read())
         {
            Console.WriteLine("db time: " + reader.GetDateTime(0).ToString());
         }
      }
   }
}

* I know, I could make it nicer, but this is a simple test for god sakes !

In one of my tests, this code produce the following output:

datetime.gif

The Sql Server 2005 Profile shows:

exec sp_executesql N'INSERT INTO CreationDates(CreationDate)VALUES(@CreationDate)',N'@CreationDate datetime',@CreationDate=''2006-04-25 14:15:26:423''


So I've sent "2006-04-25 14:15:26:421" but the database received "2006-04-25 14:15:26:423" !

Any smart ideas ??

 

Posted by Oren Ellenbogen 
25/04/2006 03:26, Israel time UTC+03:00,     Comments [4]  | 
# Sunday, April 23, 2006

I was required to update 40+ tables in our DB; Moran Benisty, our DBA master gave me a cool solution:

SELECT 
   'update ' + name + ' set SomeColumn = ''SomeValue'' where OtherColumn = ''SomeOtherValueToMatchBy'''
FROM 
   sys.objects
WHERE 
   name LIKE 'LK_%'



Now all I had to do is copy the results and run them. Sweet !

BTW - use at your own risk. :)

Posted by Oren Ellenbogen 
23/04/2006 04:42, Israel time UTC+03:00,     Comments [2]  | 
# Friday, April 21, 2006

There are *a lot* of posts out there about interview questions we should all be familiar with before going to an interview for a developer\architect position. I'm not going to add more to that Q&A list but rather to talk about how many interviews you should go to while looking for a job talk and how you should talk, react and respond during those interviews. I want to share with you my experience in the field both from interviewee and interviewer point of views. Maybe this will enable you to get some more $$$ to your paycheck, maybe it will make you simply more confident during those interviews or maybe I would be able to answer some of the questions you've got and still nobody answered before.

I'm looking for a job, when should I say "That's enough interviews, let's sign" ?

I would say between 5-10 *successful* interviews. That means that you have at least 5 proposals from companies you're interested working for, even if 1-2 of them are out of the question due to the low payment. Less than 5 proposals will not give you the right impression about "how much am I worth?" so don't hurry to sign, you don't want to get stuck in a company just because they offered X$ more than the rest and you thought it was a lot. I know, you can always resign, but this is still a waste of time. Doing many interviews, on the other hand, can burn you which means you'll go to your 11th or 12th interview and don't give your best, that's a shame; Don't forget, your reputation is at stake and our industry is a small world.

Know how to walk the walk, but learn how to talk the talk:

Listen, an interview is like a blind date, you must create a great first impression if you want to get to second base (that means passing to the next phase in the screening, in our case). Therefore you must grasp the nature of technical people and press the right buttons and even more important - don't press the wrong ones. I know, learning how to talk and sell yourself is very hard to master, some of us are just born with it, some of us just think we have it, some of us learn how to do it during the years and some don't count on it ("I'll be good and that should be enough!"). If you're one of the latter, meaning that you know you're good and you think that should be enough.... you're damn right! BUT! you won't get the payment you deserve, trust me, so continue reading, maybe you can learn some good tips.

In an interview you must convey me that you have the confidence I seek. See, we all want to hire people we can trust: trust that they can do their job even in stressful times, trust their abilities to learn new things and to teach others. Just be relaxed, have faith in yourself and in your abilities. All of us are nervous during  interviews, we all want to impress, but over-motivation will get you eliminated, you'll simply cause the interviewer to be more anxious and try to make you sweat harder("The interviewer must be better than the interviewee" symptom); This is not the impression you would like to leave.

So, how do you learn to talk the talk? That's an hard question, but I've got a simple answer - search for a person(s) in your life who you feel does a good marketing for himself and start looking, listening and understand the way he talks and behaves around people. Try to stay close to that guy as he will make you move in the direction you want and will help you work on your PR(public relations) skills. After some time will pass you'll feel more confident and that will allow you to be "rude" enough to push yourself and be confident about your abilities. That's it.

Some tips about "talk the talk" during the interview from an interviewer point of view:

  1. Be relaxed. No interviewer wants to make you fail, he just want to make you sweat a little to see if you're up to the job.
  2. Have confidence in your abilities. An interviewer can smell lack of confidence and this will make you harder to excel during the interview. Have a "pep" talk with yourself before - "I'm not the best programmer, yea, I don't know how to write multi-thread applications, but I have the ability to learn, I have the passion for this job, I'm a good at X, Y and Z! yes! I've got a lot to offer". When I was 16 and I got my first job (PHP programmer), I really believed that I can be great if someone would give me a chance. Why? Because I knew that I love programming and I'll do anything to be good at it! you want me to work extra hours? to read at home? NO PROBLEM! Bring it on!
    This is the attitude you need in order to be a GREAT interviewee. Do it with passion!
  3. Think before you answer. This is the most important tip I can give to anyone. Numerous interviewees I've interviewed were eager to let me know how bright they are. They didn't even let me finish the question. Relax (see section 1), let the interviewer complete his question and think before you answer. I would like to hear something "That's a good question, give me a few seconds to think..... OK, so what you can do is ....". This shows that you don't hurry to pull something out of your sleeve just to meet "he asked, I replied" rule a lot of follows.
  4. Don't have the answer? nothing happened! Relax! (I would write see section 1, but I think you got the point right?)
    All you have to do is simply tell me "To be honest, I don't remember\know how to solve this question, BUT, if I had google, MSDN (whatever) - I would likely search "XXXXXX". In addition, let me think out loud about possible solutions to your question... OK so you can (1)XXXXX or maybe (2)XXXXX, I'm not sure but perhaps (3)XXXX will work as well". This will certainly make a good impression. Nobody can memorize MSDN and none of us has enough experience to cover 100% of the questions. Good interviewees just know how to stay cool and think out loud; Explain your way to the solution and I'll show you the way to the job and paycheck you seek.
  5. You're good, I have no doubt, but there are others who are better, I have no doubt. arrogance is a quality you must avoid or at least decrease. Nobody like arrogant people although I truly believe that there is a thin line between self confidence and arrogance. Try to stay humble, let them know that you have more than good programmer skills to contribute; Do it with grace.


Any tips you would like to share with me ?

Posted by Oren Ellenbogen 
21/04/2006 12:09, Israel time UTC+03:00,     Comments [0]  | 
# Thursday, April 13, 2006

I've joined Microsoft Israel community so you can now find some of my post in this address:

http://blogs.microsoft.co.il/blogs/orenellenbogen/

I'll publish a few advanced post in Hebrew in the following month so stay updated.

.NET | Life
Posted by Oren Ellenbogen 
13/04/2006 07:08, Israel time UTC+03:00,     Comments [0]  |