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.
# Friday, May 12, 2006

So it all began on Tuesday, Moty (CEO), Roee(CTO), Ken (Team Leader and a major guffy) and myself drove about 5 hours to Eilat...
Posted by Oren Ellenbogen 
12/05/2006 09:30, Israel time UTC+03:00,     Comments [0]  | 

Man, that was a good 3 days of great lectures, great people and one great great party ! I had so much fun, really, and I'll try to share with my enthusiasm during the following 2-3 posts. Prepare for plenty of reviews about the lectures I've went to and a big set of pictures.

I got a lot of inspiration from some of the lecturers at TechEd and I can't tell you how much I'm excited about my lecture this week, I've invested a tremendous amount of time in it so I hope it will turn out the way I'm want it to be. It will be a dream come true to lecture on one of the next TechEd, so I hope I'll have some chances to share with you my motivation and my passion about our world(programming rules!).

All in time, I guess.

OK - on to the next post !

Posted by Oren Ellenbogen 
12/05/2006 08:56, Israel time UTC+03:00,     Comments [0]  | 
# 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]  |